Skip to main content
Stream text-to-speech audio in real-time using WebSocket connections. Perfect for conversational AI applications that need low-latency audio synthesis.

When to Use WebSocket TTS

Best for: Real-time conversational AI, voice agents, and applications needing continuous TTS streaming with multiple concurrent requests. Visit this tutorial for an implementation.

Key Benefits

  • Low latency: ~300ms to first audio chunk
  • Multiple requests: Handle multiple synthesis requests on single connection
  • Real-time streaming: Audio chunks stream as they’re generated
  • Persistent connection: Reuse connection for entire conversation

Connection

Endpoint

Authentication

Connect using your API key:

Message Protocol

All messages use a unified format with a type field.

Client → Server Messages

Synthesize Text

Parameters:
  • requestId: Unique ID for tracking this request
  • text: Text to synthesize (max 10,000 characters)
  • voiceId: Voice to use (e.g., “v_meklc281” for Urdu female)
  • outputFormat: Audio format (optional, defaults to PCM_22050_16)

Cancel Request

Server → Client Messages

All server messages come through the message event:

Connection Ready

Audio Start

Audio Chunk

Audio End

Error

Simple Example

Output Formats

Available Voices

Use the same voice IDs as REST API:
  • v_meklc281 - Urdu female
  • v_8eelc901 - Info/Education
  • v_30s70t3a - Nostalgic News
  • v_yypgzenx - Dada Jee (storytelling)

Error Codes

Rate Limits

  • Synthesis requests: 60 per minute per connection
  • Cancel requests: 100 per minute per connection
  • Max text length: 10,000 characters per request
  • Daily limit: Based on your plan

Best Practices

Generate unique IDs (like UUIDs) for each synthesis request to track audio chunks properly.
Keep one WebSocket connection open and reuse it for multiple synthesis requests.
Collect audio chunks before playback for smooth streaming experience.
Implement exponential backoff for reconnection attempts on connection loss.

Testing with wscat

Quick test using command line:

Next Steps

WebSocket Tutorial

Build a conversational AI app

Voice Samples

Listen to available voices