Skip to main content
You need a working knowledge of the WebSocket protocol. These examples use the Deepgram Aura model; swap the endpoint path to use a different provider. WebSockets let you stream audio with sub-100ms latency and stop mid-sentence, which is what you need for voice agent conversations. If you only need to generate audio files, HTTP is simpler.

Placeholders

The snippets below use these placeholders. Replace them before running the code.

Message Flow

Every TTS WebSocket session follows this pattern: For the full list of message types and parameters, see the WebSocket protocol reference. To keep acronyms, names, and domain terms consistent during synthesis, set a session default or per-turn pronunciation dictionary.

Quick Start

Connect, initialize a session, send text, and save the audio to a file. Both examples write a output.pcm file containing raw 16-bit PCM audio at 24 kHz. You can play it with ffplay:

More Examples

Batch Text Streaming

Send multiple sentences for smoother speech instead of one large block. This is a complete example you can run independently.

Next Steps

Live TTS demo

Try real-time TTS in your browser, no setup needed

WebSocket protocol

Full message types, parameters, and error codes

Pronunciation dictionaries

Reuse pronunciation rules across TTS requests

TTS HTTP examples

Simpler integration for non-streaming use cases

TTS API reference

Endpoint-specific parameters