Skip to content

Fix Telnyx: enable bidirectional streaming so caller hears TTS audio - #8

Open
lucaspfingsten wants to merge 1 commit into
deepgram:mainfrom
lucaspfingsten:fix/telnyx-bidirectional-streaming
Open

Fix Telnyx: enable bidirectional streaming so caller hears TTS audio#8
lucaspfingsten wants to merge 1 commit into
deepgram:mainfrom
lucaspfingsten:fix/telnyx-bidirectional-streaming

Conversation

@lucaspfingsten

Copy link
Copy Markdown

Summary

Fixes #6.

The Telnyx actions/answer payload in deepclaw/voice_agent_server.py only set stream_url and stream_track, which opens an inbound-only media stream. Telnyx forwards caller audio to the WebSocket but silently drops anything sent back, so Deepgram's TTS frames never reach the caller — the call appears one-way and the caller hears nothing.

This adds the two fields needed to flip the stream into bidirectional mode:

"stream_bidirectional_mode": "rtp",
"stream_bidirectional_codec": "PCMU",

PCMU matches the codec the existing telnyx_media_websocket receive loop already assumes (see the BUFFER_SIZE = 20 * 160 # 0.4 seconds at 8kHz PCMU comment).

Test plan

  • Verified locally end-to-end: inbound PSTN call via Telnyx → caller speech is transcribed by Deepgram → agent TTS plays back to the caller in real time.
  • Tunnel: ngrok over HTTPS. (Issue Telnyx: caller cannot hear TTS audio (outbound audio silent) #6's reporter is behind a Caddy reverse proxy and reported this same change didn't help in their setup — so this fix may not be sufficient on every network path, but on a vanilla ngrok setup it resolves the symptom.)
  • Maintainers / @team-telnyx: would appreciate a sanity check on whether mode: "rtp" is the right choice here vs. mode: "mp4". The existing receive code already sends audio back as base64 media events over the WebSocket, which works under rtp in my testing but is worth confirming against Telnyx's preferred path.

Notes on scope

Kept the change minimal — only the two new fields plus a short comment explaining why they're required. Happy to extend with stream_bidirectional_sampling_rate: 8000 and stream_bidirectional_target_legs: "opposite" (both Telnyx defaults today, but defensive for future API changes) if reviewers prefer.

The Telnyx `actions/answer` payload was sending only `stream_url` and
`stream_track`, which opens an inbound-only media stream — Telnyx forwards
caller audio to the WebSocket but silently drops anything the server sends
back. The Deepgram Voice Agent's TTS frames are emitted but never reach the
caller, so the call appears one-way.

Setting `stream_bidirectional_mode: "rtp"` switches Telnyx into bidirectional
mode, and `stream_bidirectional_codec: "PCMU"` aligns the outbound codec with
what the existing `telnyx_media_websocket` receive loop already sends back
(PCMU/8kHz, matching the inbound `BUFFER_SIZE` comment at line 532).

Fixes deepgram#6.
@lucaspfingsten
lucaspfingsten force-pushed the fix/telnyx-bidirectional-streaming branch from 191e838 to cff1e71 Compare April 29, 2026 21:16
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.

Telnyx: caller cannot hear TTS audio (outbound audio silent)

1 participant