Commit a0c221d
fix: handle odd-length audio chunks in voice streaming (fixes #1824)
This change fixes a ValueError that occurred when audio chunks from TTS
providers (e.g., ElevenLabs MP3 streams) had an odd number of bytes.
The issue was in StreamedAudioResult._transform_audio_buffer which used
np.frombuffer with dtype=np.int16. Since int16 requires 2 bytes per element,
buffers with odd byte lengths would cause:
ValueError: buffer size must be a multiple of element size
Solution:
- Pad the combined buffer with a zero byte if it has odd length
- This ensures the buffer size is always a multiple of 2 bytes
- The padding has minimal audio impact (< 1 sample)
The fix applies to all TTS providers that may produce odd-length chunks,
not just ElevenLabs.
Testing:
- Linting (ruff check) - passed
- Type checking (mypy) - passed
- Formatting (ruff format) - passed
Generated with Lucas Wang<[email protected]>
Co-Authored-By: Claude <[email protected]>1 parent 748ac80 commit a0c221d
1 file changed
+10
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
| |||
0 commit comments