Documentation Index
Fetch the complete documentation index at: https://docs.getpatter.com/llms.txt
Use this file to discover all available pages before exploring further.
ElevenLabs WebSocket TTS
ElevenLabsWebSocketTTS is a drop-in alternative to ElevenLabsTTS that streams audio over a WebSocket connection instead of the standard HTTP streaming endpoint. The public API is identical to the HTTP variant — the only difference is the transport.
Why use it
The WebSocket variant saves roughly 50 ms of HTTP setup + TLS cold-start per utterance compared toElevenLabsTTS. On chatty conversational workloads this shaves real time off every agent turn. Use it when:
- You are latency-bound on TTS time-to-first-byte.
- Your model is one of the streaming-friendly
eleven_flash_v2_5/eleven_turbo_v2_5families. - You do not need
eleven_v3*(see Limitations).
Install
Usage
Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
apiKey | string | — | API key. Reads from ELEVENLABS_API_KEY if omitted. |
voiceId | string | "21m00Tcm4TlvDq8ikWAM" (Rachel) | ElevenLabs voice ID. |
modelId | string | "eleven_flash_v2_5" | Model preset. Must be a streaming-compatible model. |
outputFormat | string | "pcm_16000" | ElevenLabs output format. Use "ulaw_8000" for Twilio, "pcm_16000" for Telnyx. |
voiceSettings | VoiceSettings | — | Stability, similarity boost, style, and speaker boost overrides. |
languageCode | string | — | BCP-47 language code forwarded to ElevenLabs. |
autoMode | boolean | true | Server-side automatic flushing when the input ends. |
inactivityTimeout | number | 60 | Seconds the WebSocket stays open without input before the server closes it. |
chunkLengthSchedule | number[] | — | Server-side chunking schedule for streamed text. |
chunkSize | number | — | Audio chunk size hint for the receive side. |
Limitations
eleven_v3*is not supported. The v3 model family does not work over the WebSocket transport — fall back to the HTTPElevenLabsTTSfor those models.- Per-utterance lifecycle. A fresh WebSocket connection is opened and closed for each agent utterance. The latency win comes from a faster handshake, not from session reuse.
- Network sensitivity. WebSocket connections are more sensitive to flaky links than short-lived HTTP requests. On unreliable networks the HTTP variant is safer.
Errors
ElevenLabsTTSError is thrown on:
- Server-reported errors over the WebSocket frame.
- Stalled connections (no audio frames received within the inactivity window).
- Authentication failures (missing or invalid
apiKey).

