Skip to content

Conversation

@Nisarg38
Copy link
Contributor

@Nisarg38 Nisarg38 commented Oct 8, 2025

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.

Deepgram SDK Reference

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.
@CLAassistant
Copy link

CLAassistant commented Oct 8, 2025

CLA assistant check
All committers have signed the CLA.

- Added _FLUSH_MSG constant to SynthesizeStream class
- Updated _close_ws method to send Flush and Close messages
- Implemented server acknowledgment wait to ensure proper cleanup
@Nisarg38 Nisarg38 requested a review from davidzhao October 9, 2025 18:18
Copy link

@jeniya-DG jeniya-DG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@davidzhao davidzhao merged commit 1a5a9d3 into livekit:main Oct 12, 2025
8 checks passed
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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants