-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(deepgram): send CloseStream message before closing TTS WebSocket #3608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davidzhao
merged 3 commits into
livekit:main
from
Nisarg38:fix/deepgram-tts-stream-closure
Oct 12, 2025
Merged
fix(deepgram): send CloseStream message before closing TTS WebSocket #3608
davidzhao
merged 3 commits into
livekit:main
from
Nisarg38:fix/deepgram-tts-stream-closure
Oct 12, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes an issue where the Deepgram TTS plugin was not sending the
CloseStream control message before closing WebSocket connections,
which could result in audio truncation or incomplete processing.
Changes:
- Added _CLOSE_MSG constant to SynthesizeStream class
- Updated _close_ws method to send CloseStream message before closing
- Added error handling and brief wait for final messages from Deepgram
This aligns the TTS implementation with:
1. Deepgram's current API requirements for graceful stream closure
2. The existing STT implementation which already correctly sends CloseStream
Background:
Deepgram updated their real-time API to require a JSON control message
{"type": "CloseStream"} instead of just closing the connection, to
ensure all remaining audio is processed and all transcripts/audio are
returned before the connection terminates.
davidzhao
reviewed
Oct 9, 2025
livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/tts.py
Outdated
Show resolved
Hide resolved
jeniya-DG
reviewed
Oct 9, 2025
livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/tts.py
Show resolved
Hide resolved
jeniya-DG
approved these changes
Oct 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
davidzhao
approved these changes
Oct 12, 2025
akshaym1shra
pushed a commit
to akshaym1shra/agents
that referenced
this pull request
Oct 28, 2025
akshaym1shra
pushed a commit
to akshaym1shra/agents
that referenced
this pull request
Oct 28, 2025
meetakshay99
added a commit
to meetakshay99/agents
that referenced
this pull request
Oct 30, 2025
* staging: (114 commits) Added min_confidence_threshold for deepgram flux. livekit-agents 1.2.15 (livekit#3658) fix livekit#3650 cartesia version backward compatibility (livekit#3651) Unprompted STT Reconnection at startup (livekit#3649) enable zero retention mode in elevenlabs (livekit#3647) fix: heartbeat (livekit#3648) feat: Integrate streaming endpoints for Sarvam APIs (livekit#3498) turn_detection: reduce max_endpointing_delay to 3s (livekit#3640) fix: exclude temperature parameter for gpt-5 and similar models (livekit#3573) add backwards compatibility for google's realtime model (livekit#3630) Align Google STT plugin with official documentation (livekit#3628) feat(speechmatics): add max_speakers parameter for speaker diarization (livekit#3524) fix(deepgram): send CloseStream message before closing TTS WebSocket (livekit#3608) chore: Remove duplicate docstring for `preemptive_generation` parameter in AgentSession (livekit#3624) Add RTZR(ReturnZero) STT Plugin for LiveKit Agents (livekit#3376) feat(telemetry/utils): add ttft reporting to LangFuse (livekit#3594) catch delete_room errors and disable delete_room_on_close by default (livekit#3600) lift google realtime api out of beta (livekit#3614) fix: lock pyav to <16 due to build issue (livekit#3593) Updating Cartesia Version (livekit#3570) ...
akshaym1shra
pushed a commit
to akshaym1shra/agents
that referenced
this pull request
Nov 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes an issue where the Deepgram TTS plugin was not sending the CloseStream control message before closing WebSocket connections, which could result in audio truncation or incomplete processing.
Changes:
This aligns the TTS implementation with:
Background:
Deepgram updated their real-time API to require a JSON control message {"type": "CloseStream"} instead of just closing the connection, to ensure all remaining audio is processed and all transcripts/audio are returned before the connection terminates.
Deepgram SDK Reference