Stream text to speech over WebSocket
Open a WebSocket connection to stream text and receive synthesized audio in real time. Authentication is provided via the standard Authorization: Bearer <API_KEY> header. Send JSON frames with text to synthesize; receive JSON frames containing base64-encoded audio chunks.
Supported providers: aws, telnyx, azure, murfai, minimax, rime, resemble, elevenlabs, xai, humain.
Connection flow:
- Open WebSocket with query parameters specifying provider, voice, and model.
- Send an initial handshake message {"text": " "} (single space) with optional voice_settings to initialize the session.
- Send text messages as {"text": "Hello world"}.
- Receive audio chunks as JSON frames with base64-encoded audio.
- A final frame with isFinal: true indicates the end of audio for the current text.
To interrupt and restart synthesis mid-stream, send {"force": true} — the current worker is stopped and a new one is started.
Note: The Telnyx Ultra model is not available over WebSocket. Use the HTTP POST /text-to-speech/speech endpoint instead.
Query parameters
Voice identifier in the format provider.model_id.voice_id or provider.voice_id (e.g. telnyx.NaturalHD.Telnyx_Alloy, Telnyx.Ultra.<voice_id>, Telnyx.Bayan.Ahmed, Telnyx.Sukhan.urdu-professor, or azure.en-US-AvaMultilingualNeural). When provided, the provider, model_id, and voice_id are extracted automatically. Takes precedence over individual provider/model_id/voice_id parameters.
TTS provider. Defaults to telnyx if not specified. Ignored when voice is provided.
Model identifier for the chosen provider. Examples: Natural, NaturalHD, Ultra (Telnyx); Polly.Generative (AWS).
Voice identifier for the chosen provider.
When true, bypass the audio cache and generate fresh audio.
Audio output format override. Supported for Telnyx models. pcm and wav are available for Natural/NaturalHD models. The Ultra model outputs PCM at 24kHz s16le or MP3 at 128kbps 24kHz.
Client-provided socket identifier for tracking. If not provided, one is generated server-side.
Response
WebSocket upgrade successful — this response is not returned directly. See 101 for frame documentation.