fix(audio): discard pending resampler audio on buffer reset - #7405
Open
YaoxinHuang wants to merge 2 commits into
Open
YaoxinHuang wants to merge 2 commits into
YaoxinHuang wants to merge 2 commits into
Conversation
Start a fresh resampling stream after reset so audio from the previous speech segment cannot leak into the next segment.
Use the native RTC resampler at 8, 24, and 48 kHz and allow a small tolerance for PCM dithering.
This branch has not been deployed
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.
AudioArrayBuffer.reset()clears the NumPy buffer but keeps the resampler and its delayed samples. After reset, pushing silence can emit audio from the previous segment. The interruption detector resets this buffer at agent-speech boundaries.Discard the resampler on reset so the next frame starts a fresh resampling stream. Tests use the real RTC resampler at 8, 24, and 48 kHz and check that previously buffered audio does not leak into the next segment; a small tolerance accommodates native PCM dithering.
Validation:
python -m pytest tests/test_utils/test_audio_array_buffer.py --unit -q: 49 passed. The three new cases fail before the fix; the existing 46 pass.python -m mypy --platform linux -m livekit.agents.utils.audio: passes.Repository-wide formatting reports 15 pre-existing files outside this diff. The full provider suite and all-plugin type check were not run. No model weights or service credentials were used.
Prepared and tested with Codex.