Skip to main content

TTS WebSocket API

Real-time Text-to-Speech synthesis via WebSocket streaming with full-duplex bidirectional communication.

🚀 Quick Start (Copy & Paste)

That’s it! You’ll see:
  • ✅ Authenticated
  • ✅ Context created
  • 🔊 Audio chunk: 1024 bytes (multiple times)
  • ✅ All audio received!
  • ✅ Complete!
  • 💾 Saved: output.pcm

📖 How It Works (5 Simple Steps)

  1. Connect with your API key
  2. Create a context with voice settings
  3. Send your text message
  4. Flush to trigger synthesis
  5. Close when done (receive audio file)

Endpoint

Authentication

Query parameter authentication: Example:

Protocol Overview

Connection Sequence

1. Connect

2. Receive Authentication Message

3. Receive Connection Established

Fields:
string
Service name: "tts"
integer
Your user ID
number
Available credits
string
Workspace name

Client → Server Messages

1. create_context

Must be the first message. Initializes the TTS session with voice and audio settings.
Parameters: Supported encoding + sample rate combinations:
Note: MULAW/ULAW only works at 8000 Hz. OGG_OPUS only works at 24000 Hz.
Limits:

2. send_text

Append text to the internal buffer. Text is accumulated until a flush_context or close_context is received.
Fields: You can send multiple send_text messages to build up text incrementally (e.g., from an LLM token stream):

3. flush_context

Triggers synthesis of all accumulated text. The server responds with audio_chunk messages followed by flush_completed.

4. close_context

Flushes any remaining text, sends final audio, and closes the WebSocket connection.

Server → Client Messages

context_created

Confirms the session was initialized successfully.

audio_chunk

Contains a chunk of synthesized audio. Multiple chunks are sent per flush.
Fields:
string
Session identifier
string
Base64-encoded audio bytes
The audio encoding and chunk format depend on audio_config:

flush_completed

Signals that all audio for the flushed text has been sent.

context_closed

Confirms the session is closed. The WebSocket connection closes after this message.

error

Sent if synthesis fails or a protocol violation occurs.
Common errors:

Complete Example

    Audio Configuration

    For telephony integration (Twilio, etc.), use MULAW at 8000 Hz.

    Default Voice

    The default voice ID is:
    To get more voices, use the Voices API.

    Context Management

    Reuse Context

    Keep a context open for multiple syntheses:

    Multiple Contexts

    You can create multiple contexts in one connection:

    Supported Languages

    The TTS model supports synthesis in multiple Indic languages and English. The language is auto-detected from the input text.

    Pricing

    • Rate: $0.00002 per character
    • Minimum: $0.01 per context
    • Billing: Per character synthesized