Repository navigation
Conversation
gemini-3.8 TTS models return a complete RIFF file. The speech bridge always added another WAV header, so players treated the inner header as samples Developed with assistance from Cursor (Grok).
|
| data_index: Final = audio.find(b"data", 12) | ||
| if data_index < 12: | ||
| return audio | ||
| return audio[data_index + 8 :] |
There was a problem hiding this comment.
| return _pcm16_payload(decoded_audio), "audio/pcm" | ||
| if decoded_audio.startswith(b"RIFF") and decoded_audio[8:12] == b"WAVE": | ||
| return decoded_audio, "audio/wav" |
There was a problem hiding this comment.
Provider handling outside llms The new Gemini WAV stripping and passthrough logic lives in the speech bridge. Repository instructions require provider-specific handling under
llms/; this requirement must be satisfied before merging
Rule Used: What: Avoid writing provider-specific code outside of the llms/ directory. Why: This practice ensures better maintainability and reduces complexity over time. Good: ```python # Handle provider-specific logic within llms/vertex_ai/transformation.py ... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Gemini-specific PCM/WAV wrapping lived in the shared speech bridge. It now lives under litellm/llms/gemini, and PCM extraction walks RIFF chunks so a LIST chunk before data is not treated as samples Developed with assistance from Cursor (Grok).
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
How it solves it:
response_format=pcm, strip to the data chunk onlyUser Flow
Before: a developer calling Gemini TTS gets a double-header WAV that sounds like noise
audio/wavbytes that start with RIFFAfter: the same call returns a single clean WAV (or raw PCM when requested)
response_format=pcm, the body is raw PCM samples with no RIFF wrapperRelevant issues
Closes #44541
Screenshots / Proof of Fix
Unit coverage is on the public
litellm.speechpath (14 passed; new tests fail when the fix is reverted). Live Gemini TTS curl before/after was not re-run in this session — replace this section with a tip SHA before/after once you have a live recording if maintainers want e2e proof.Before (
be4481779e/ main without fix)/v1/audio/speechfor a gemini TTS model that returns WAVAfter (
736abf07474d31a3b9ceef58bfa1298e2f91156a)/v1/audio/speechcallresponse_format=pcmreturns raw PCM onlyType
🐛 Bug Fix
Caveats (if any)
Low
Developed with assistance from Cursor (Grok).