Streaming Text-to-Speech API Documentation
Stream AI-generated speech in real time with low-latency audio delivery, playback support, and voice synthesis APIs.
WebSocket Connection
wss://api.voxentis.com/v1/tts/stream?voice_id=pNInz6obpg&format=pcm16
Query Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| voice_id | string | ✓ | Voice identifier |
| format | string | "pcm16", "opus", "mp3" (default: pcm16) | |
| sample_rate | integer | Output sample rate (default: 24000) | |
| speed | number | Playback speed 0.5-2.0 (default: 1.0) |
Sending Text
{"type": "text", "content": "Hello! "}
{"type": "text", "content": "How can I "}
{"type": "text", "content": "help you today?"}
// Signal end of text to flush remaining audio
{"type": "flush"}
// Close the connection
{"type": "close"}
Python — Stream TTS from LLM
import asyncio
import websockets
import json
async def stream_tts(llm_tokens):
uri = "wss://api.voxentis.com/v1/tts/stream?voice_id=pNInz6obpg"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
async with websockets.connect(uri, extra_headers=headers) as ws:
async def receive_audio():
async for message in ws:
if isinstance(message, bytes):
play_audio(message)
receiver = asyncio.create_task(receive_audio())
for token in llm_tokens:
await ws.send(json.dumps({
"type": "text",
"content": token
}))
await ws.send(json.dumps({"type": "flush"}))
await asyncio.sleep(1)
await ws.send(json.dumps({"type": "close"}))
await receiver
Ultra-Low Latency: Streaming TTS produces the first audio frame within ~200ms of receiving text.
Handling Interruptions
If the caller interrupts while the agent is speaking, send a cancel message to stop audio generation immediately:
{"type": "cancel"}
When used within a Voxentis voice agent, streaming TTS and interruption handling are managed automatically by the pipeline.