fix: prevent ValueError when audio buffer is empty in STT (fixes #821) #1934
+2
−1
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 #821
This PR prevents a
ValueError
crash when the audio buffer is empty in the STT transcription pipeline.Problem
When
_turn_audio_buffer
is empty, calling_audio_to_base64()
triggers:This occurs at line 126 in
openai_stt.py
:When This Happens
Solution
Add a simple check before calling
_audio_to_base64()
:The additional
and self._turn_audio_buffer
check ensures we only encode when there's actual data.How to Test
Test 1: Reproduce the Original Bug
Create a file
test_bug.py
:Run:
python test_bug.py
Expected: Shows the
ValueError
that users reported in issue #821Test 2: Verify the Fix
Create a file
test_fix.py
:Run:
python test_fix.py
Expected output:
Test 3: Run Existing Test Suite
Impact
Code Quality