Skip to content

Replace callback-based audio streaming with iterator pattern#597

Merged
baijumeswani merged 2 commits intomainfrom
copilot/update-audio-client-transcription
Apr 6, 2026
Merged

Replace callback-based audio streaming with iterator pattern#597
baijumeswani merged 2 commits intomainfrom
copilot/update-audio-client-transcription

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

AudioClient.transcribe_streaming required a callback argument, inconsistent with ChatClient.complete_streaming_chat which returns a Generator. Align the audio client to the same iterator pattern used across the SDK.

Changes

  • audio_client.py: Replace transcribe_streaming(path, callback) -> None with transcribe_streaming(path) -> Generator[AudioTranscriptionResponse] using the same threading.Thread + queue.Queue + sentinel pattern from ChatClient._stream_chunks
  • test_audio_client.py: Update streaming tests to for chunk in consumption; remove test_should_raise_for_streaming_invalid_callback (no longer applicable)
  • test/README.md: Update test counts (7→6 audio, 32→31 total)

Usage

# Before
def on_chunk(chunk):
    print(chunk.text)
audio_client.transcribe_streaming("recording.mp3", on_chunk)

# After
for chunk in audio_client.transcribe_streaming("recording.mp3"):
    print(chunk.text)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview, Comment Apr 6, 2026 8:51pm

Request Review

@baijumeswani baijumeswani marked this pull request as ready for review April 6, 2026 06:05
@baijumeswani baijumeswani requested review from Copilot and prathikr April 6, 2026 06:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the Python AudioClient.transcribe_streaming API with the SDK’s iterator-based streaming pattern (matching ChatClient.complete_streaming_chat) by switching from a required callback to a returned generator.

Changes:

  • Refactor transcribe_streaming to return a Generator[AudioTranscriptionResponse] backed by a background thread + queue + sentinel.
  • Update audio streaming tests to consume streaming output via for chunk in ... and remove the invalid-callback test.
  • Update Python test suite README test counts to reflect the removed test.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
sdk/python/src/openai/audio_client.py Replaces callback-based streaming with a generator-based streaming implementation using a thread/queue pattern.
sdk/python/test/openai/test_audio_client.py Updates streaming tests to iterate over the generator; removes callback validation test.
sdk/python/test/README.md Updates listed audio/total test counts after removing one test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@baijumeswani baijumeswani enabled auto-merge (squash) April 6, 2026 20:52
@baijumeswani baijumeswani merged commit c3e5841 into main Apr 6, 2026
42 checks passed
@baijumeswani baijumeswani deleted the copilot/update-audio-client-transcription branch April 6, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants