Repository navigation
fix(gemini): return raw pcm16 when Gemini TTS answers WAV audio on lts/1.108.x - #54193
mateo-berri merged 6 commits into
Conversation
(cherry picked from commit 2490a55)
…annot read Lyria music asked for as WAV is 48 kHz stereo, so stripping its header lost the rate and channels. Only a 24 kHz mono 16-bit WAV is unwrapped now, and audio that fails to decode or parse comes back unchanged instead of raising. (cherry picked from commit 9339b4b)
…n speech Pass through audio/wav base64 that is not strict base64, including non-ASCII and URL-safe input, unwrap WAV sent as a data URI text part, and return audio that is already a WAV container from /v1/audio/speech as is (cherry picked from commit ca840c6)
…ini route Picked from BerriAI#51145 commits 1ba64fb, 6d57373, efcc5d4, 1f5446e, d34fc9c, bd5452a, fd0ef57, c703997 and d875f7d, applied as one change since their diffs touch main-only context LTS adaptations: no thought_signature_in_tool_call_id or speech-config normalization here, the speech bridge takes no model argument, the cache key leaves out extra_body as LTS always has, streamed chat audio is not surfaced on LTS so the streamed tests are dropped, and the native logging test calls the LTS success-logging entry point
…_tts_wav_to_pcm16_lts
[Medium impact] The PR appears safe to merge, with no outstanding findings
|
|
bugbot run |
| }: | ||
| return bool(mime_type) | ||
| case _: | ||
| return False |
There was a problem hiding this comment.
Snake-case audio ask ignored beside camelCase
Medium Severity
requests_audio_mime_type picks generationConfig or generation_config with or, so a truthy camelCase config hides a snake-case mime ask. A chat call that sets modalities/audio (which fills generationConfig) and names AUDIO_WAV only under extra_body.generation_config is treated as a no-ask and unwrapped to PCM. That extra_body shape is an explicitly supported path, so the caller gets raw pcm16 instead of the WAV they named.
Reviewed by Cursor Bugbot for commit d6b7d35. Configure here.
There was a problem hiding this comment.
Google answers HTTP 400 ("oneof field '_generation_config' is already set") when a body has both keys, so no response reaches the unwrap
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
1 issue from previous review remains unresolved.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 6c2a6f2. Configure here.


Backport of #51145 to lts/1.108.x. Gemini 3.8 Flash TTS sends back a WAV file where older voices sent raw audio, so chat
pcm16audio came back as WAV and/v1/audio/speechplayed a click before the voice. This strips that WAV wrapper on 1.108 too, while WAV a caller asked for by name comes back as beforeDetails
TLDR
Problem this solves:
audio/wav, older ones raw PCMformat: pcm16comes back as WAV bytes on 1.108/v1/audio/speechputs a second WAV header around that WAVHow it solves it:
User Flow
Before: a 1.108 user asking Gemini 3.8 TTS for
pcm16chat audio gets a WAV file instead"model": "gemini-3.8-flash-tts","modalities": ["audio"], and"audio": {"voice": "Kore", "format": "pcm16"}RIFFWAV header"response_format": "wav"returns a WAV with a secondRIFFheader insideAfter: the same calls return the format they name
RIFFheaderRelevant issues
Backport of #51145, which fixes #44541 on main
Picks
The first three picks applied clean apart from imports. The other nine went in as one commit, since they touch code only main has
Differences on this line
extra_bodyfor every param, so the twoextra_bodycache cases are dropped. Main keys it since fix(caching): key the response cache on extra_body by default #53898Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Last updated: 6c2a6f2. QA ran on 6c2a6f2. Verification: 2639 tests across the alias check and every test file this PR changes, and
make checkpassLive smoke on lts/1.108.x with real Gemini calls, one proxy booted from each tree with no database. The streamed cases from #51145 do not apply, since 1.108 does not stream chat audio
pcm16RIFFRIFFwavRIFFheadersRIFFheaderProxy config
Both proxies ran this config with 2 workers and no database, each booted from its own tree on a random port, with real Gemini API calls
Launch script, run as
launch.sh <tree> <port> proxy_config.yaml master_key(the base proxy on port 21463, the head proxy on port 25028)decode_chat.pycount_riff.pyBefore (d08d9d0)
(a) Chat audio with format pcm16
Send the chat request that asks for pcm16 audio
Decode the returned audio
The audio starts with
RIFF, so the caller asked for raw pcm16 and got a WAV file(b) Speech with response_format wav
Request the speech file as WAV
Count the RIFF headers in the file
The file has two
RIFFheaders, the second one at byte 44 inside the audio data(c) Chat audio with responseFormat AUDIO_WAV
Send the chat request that asks Google for WAV
Decode the returned audio
The audio starts with
RIFF, which is the WAV the caller asked Google forAfter (6c2a6f2)
(a) Chat audio with format pcm16
Send the chat request that asks for pcm16 audio
Decode the returned audio
The audio is raw 16-bit PCM with no
RIFFheader anywhere(b) Speech with response_format wav
Request the speech file as WAV
Count the RIFF headers in the file
The file has exactly one
RIFFheader, at byte 0(c) Chat audio with responseFormat AUDIO_WAV
Send the chat request that asks Google for WAV
Decode the returned audio
The audio still starts with
RIFF, so the WAV the caller asked for passes through as isType
🐛 Bug Fix
Caveats (if any)
Copied from #51145, plus one row for this line
Low
ttlnamespaceat upgrade clears itgenerationConfig,generation_configorresponseFormatmiss the cache once after the upgradepcm16generationConfig, as the OpenAI SDK'sextra_bodysends it, now gets PCM where it got WAVextra_bodyfield shares a cache entry with a no-ask callextra_bodyparam does on 1.108. Fixing it means backporting fix(caching): key the response cache on extra_body by default #53898's cache change, which is its own behavior changerouter_code_coveragecode-quality step fails on four untested router helpersFinal Attestation
Bugbot summary