fix(voice): handle odd-length audio buffers in StreamedAudioResult#2456
Open
OiPunk wants to merge 3 commits intoopenai:mainfrom
Open
fix(voice): handle odd-length audio buffers in StreamedAudioResult#2456OiPunk wants to merge 3 commits intoopenai:mainfrom
OiPunk wants to merge 3 commits intoopenai:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 039083d702
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Contributor
Author
|
Thanks for the careful catch. You were right: zero-padding every odd flush can corrupt sample boundaries when a single PCM sample is split across chunks. I pushed commit 6b10362 to address this:
Local validation:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes odd-length audio-buffer crashes in voice streaming when converting PCM chunks with
np.frombuffer(..., dtype=np.int16).Problem
StreamedAudioResult._transform_audio_buffer()assumed a 2-byte aligned buffer. If a provider emits an odd number of bytes in a chunk (observed with some MP3 streaming providers),np.frombufferraises:ValueError: buffer size must be a multiple of element sizeChanges
StreamedAudioResult._transform_audio_buffer, join buffered chunks and pad with one zero byte when the combined buffer length is odd.dtype=np.int16dtype=np.float32Why this is safe
Validation
uv run ruff check src/agents/voice/result.py tests/voice/test_pipeline.pyuv run --extra voice pytest tests/voice/test_pipeline.py -quv run --extra voice python -m trace --count --coverdir /tmp/openai_agents_1824_trace --module pytest tests/voice/test_pipeline.py -k odd_length -qFixes #1824