WIP - Add Telnyx voice provider#1461
Conversation
🦋 Changeset detectedLatest commit: 69870fb The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Oliver-Zimmerman
left a comment
There was a problem hiding this comment.
Nice port overall — I think you’ve preserved the core architecture well, especially the split between STT/TTS/telephony and the browser-side PSTN bridge model. My main ask would be to swap the example for one that better shows the real value of the provider: the current example reads mostly like a browser STT/TTS demo, while the distinctive bit here is the phone/PSTN path. I’d suggest porting one of the original phone/hybrid examples instead, e.g. examples/phone-voice-agent: https://github.com/team-telnyx/voice-cloudflare/tree/main/examples/phone-voice-agent”
|
Hey @whoiskatrin any update on this? |
|
@Oliver-Zimmerman I've picked this up and ported over the tests for future maintenance. At first glance the new example works but I wasn't able to verify the phone call working -- possibly because I've only got a freemium account. Could you validate from your side? |
|
@cjol I just tested, it is working as expected. I was able to call the genCred and have a conversation, the transcript was present. |
| import { streamText } from "ai"; | ||
| import { createWorkersAI } from "workers-ai-provider"; | ||
|
|
||
| const VoiceAgent = withVoice(Agent); |
There was a problem hiding this comment.
🔴 Example server sends MP3 audio instead of required pcm16 for phone bridge
The example's withVoice(Agent) call at examples/telnyx-voice-agent/src/server.ts:8 does not pass { audioFormat: "pcm16" } as the second argument. The voice pipeline defaults to audioFormat: "mp3" (see packages/voice/src/voice.ts:540), so the server will send MP3-encoded audio to the client. The TelnyxPhoneClient and TelnyxCallBridge.playAudio() expect 16kHz mono Int16 LE PCM — when MP3 arrives, it falls through to decodeAndPlay() which uses AudioContext.decodeAudioData(). This path adds latency, may fail on streaming chunks if the websocket TTS backend is used, and creates an AudioContext at 16kHz that might not decode MP3 correctly. The package's own README explicitly documents this: "Configure your server agent with withVoice(Agent, { audioFormat: "pcm16" }) when routing agent responses to Telnyx PSTN through the bridge."
| const VoiceAgent = withVoice(Agent); | |
| const VoiceAgent = withVoice(Agent, { audioFormat: "pcm16" }); |
Was this helpful? React with 👍 or 👎 to provide feedback.

Summary
Adds first-class Telnyx support for the Cloudflare voice pipeline, addressing #1367.
This PR introduces a new
@cloudflare/voice-telnyxprovider package undervoice-providers/telnyxand a phone/PSTN-focusedexamples/telnyx-voice-agentapp that demonstrates the browser-side Telnyx WebRTC bridge model.What changed
@cloudflare/voice-telnyxvoice-providers/*conventions.@cloudflare/voice-telnyx@cloudflare/voice-telnyx/stt@cloudflare/voice-telnyx/tts@cloudflare/voice-telnyx/telephonyTranscriber/TranscriberSession:TTSProviderandStreamingTTSProvider:TelnyxCallBridgeTelnyxPhoneTransportTelnyxPhoneClientTelnyxJWTEndpointcreateTelnyxVoiceConfigExample app
examples/telnyx-voice-agent, focused on the phone/PSTN path:createTelnyxVoiceConfigandTelnyxPhoneClientfrom@cloudflare/voice-telnyx/telephony..env.examplewith:TELNYX_API_KEYTELNYX_CREDENTIAL_CONNECTION_IDallowUnauthenticated: truewith anauthorize()callback in production.Attribution / dependency metadata
@telnyx/webrtcfor telephony support.NOTICEto document that parts of this provider are adapted from Telnyx's@telnyx/voice-cloudflarepackage, whose npm metadata declares MIT licensing.Validation
Passed:
npm run checkreports existingsherifwarnings for unrelated workspace paths withoutpackage.json, then completes successfully: export checks, formatting, oxlint, and all 82 TypeScript projects pass.Notes for reviewers
TelnyxTTScurrently returns MP3 by default andTelnyxPhoneClientcan decode non-PCM server audio before playing into the phone bridge.authorize()callback instead ofallowUnauthenticated: true.Refs #1367