Repository navigation
fix: skip batched decoding when VAD finds no speech - #555
Open
ANDROIDHASSAN wants to merge 1 commit into
Open
ANDROIDHASSAN wants to merge 1 commit into
ANDROIDHASSAN wants to merge 1 commit into
Conversation
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.
Problem
With
--batch_inference, a chunk where VAD finds no speech is still decoded when it lands in a batch of 2 or more requests.prepare_featuresonly drops the non-speech audioif speech_chunks:. Whenget_speech_timestampsreturns[], the full unfiltered chunk is kept, sospeech_durationis never0.0. The "no speech detected" early return in_process_multiis therefore never reached for VAD requests, and the whole chunk goes through encode + generate.The non-batched path (
transcriber.transcribe, also used by the batch worker for a single request) collects chunks unconditionally.collect_chunks(audio, [])returns one empty array, sotranscribereturnsNone, Noneand nothing is emitted. As a result, the same audio gives different output depending on how many sessions happen to share the batch window.Fix
prepare_featuresnow does whattranscriber.transcribedoes:With no speech, the audio is empty and
speech_durationis0.0. The existing early return then sends back[]without touching the GPU.Tests
test_vad_without_speech_skips_decoding. It runs twouse_vad=Truerequests where VAD returns[]and checks thatencodeis not called and both results are[].mainwithExpected 'encode' to not have been called. Called 1 times.pytest tests/test_batch_inference.py tests/test_batch_timeout.py: 24 passed.tests/, the results are the same as onmainapart from the new test. In my venv,maingives 109 passed and this branch gives 110. The same 2 failures and the same 8 collection errors show up on both, from optional deps I did not install (openvino, etc.).flake8with the CI's--select=E9,F63,F7,F82reports 0 on both files.Real model check, run on CPU with
tinyint8.assets/jfk.flac(first 10 s) is submitted at falling gains as 5 batcheduse_vad=Truerequests, and each result is compared withtranscriber.transcribe(..., vad_filter=True)on the same audio:maintranscribe['And so my fellow Americans ask not what your country can do for you ask what you can do for your'][][]All rows where VAD finds speech give the same output before and after the change.
Scope
One function in
whisper_live/batch_inference.pyand one test. The single-request path and the non-batched path are untouched.