Repository navigation
fix: preserve Gemini answer text in speech engine streams - #929
Conversation
PR SummaryLow Risk Overview
Regression tests drive Reviewed by Cursor Bugbot for commit 6b80669. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change preserving multipart Gemini answer text while excluding thought content.
No open issues 🎉
What changed in this PR
Fixes #928 by preserving multipart Gemini answer text in Speech Engine streams while excluding thought content. Other provider formats and first-candidate selection remain unchanged.
Changes:
- Concatenates all string-valued, non-thought text parts from the first Gemini candidate.
- Adds dictionary- and attribute-style regression tests covering mixed parts, empty responses, candidate selection, event IDs, and final-response signaling.
| File | Description |
|---|---|
tests/test_speech_engine_session.py |
Adds parameterized Gemini stream tests through send_response(). |
src/elevenlabs/speech_engine/session.py |
Collects Gemini answer text across parts, skips thoughts, and updates the extractor docstring. |
Review effort: Balanced
Join all text parts of the first candidate instead of reading only parts[0], and skip thought parts so model reasoning isn't sent to TTS. Mirrors elevenlabs/elevenlabs-python#929. Co-authored-by: Claude Opus 5.5 <[email protected]>
Fixes #928.
Speech Engine currently takes only the first part of a Gemini response chunk. A reply split into
"Hello"and" world"is spoken as"Hello"; a leading non-text part drops the answer, while a leading thought part is spoken instead of the answer.The extractor now concatenates all string-valued text parts of the first candidate and skips parts marked
thought=True. This matches Google's response text extraction. Other provider formats and the first-candidate selection remain unchanged.The change touches only the hand-maintained Speech Engine session and its existing test file, both covered by
.fernignore. The new tests exercisesend_response()with dictionary and attribute-style chunks, including mixed parts, thought-only responses, empty text, candidate selection, event IDs and final-response signaling. They are distinct from #878's helper characterization tests.Validation on Python 3.11:
mypy src/elevenlabs/speech_engine/session.py tests/test_speech_engine_session.py: passed.git diff --check: passed.This uses response fixtures, without live Gemini or ElevenLabs API calls.
Hosted validation of exact commit
6b806692300b0079adce3652dc9f910638c1a3e7: fork offline CI passed on Python 3.8, 3.13 and 3.14 (238 tests per version), including test lint, a Python 3.8 type check and a Python 3.13 wheel build. The workflow lives only on a separate fork validation branch, outside this PR.The native Python 3.14 job passes 357 tests and fails 16 live API tests with HTTP 401 because the fork lacks an API credential. The unchanged upstream baseline fails the identical 16 tests. The native suite is therefore not reported as green.