Audio
Create realtime text-to-speech
Establishes a WebSocket connection for real-time text-to-speech generation. This endpoint uses WebSocket protocol (wss://api.together.ai/v1/audio/speech/websocket) for bidirectional streaming communication.
Connection Setup:
- Protocol: WebSocket (wss://)
- Authentication: Pass API key as Bearer token in Authorization header
- Parameters: Sent as query parameters (model, voice, max_partial_length, language)
Client Events:
tts_session.updated: Update session parameters like voice. Thesessionobject also accepts anextra_paramsfield for additional model-specific parameters that fine-tune speech generation behavior, such aspronunciation_dict(a list of pronunciation rules for specific characters or symbols, where each entry uses the format"<source>/<replacement>"(e.g.,["omg/oh my god"]) to override how the model pronounces matching tokens).input_text_buffer.append: Send text chunks for TTS generationinput_text_buffer.clear: Clear the buffered textinput_text_buffer.commit: Signal end of text input and process remaining text
Server Events:
session.created: Initial session confirmation (sent first)conversation.item.input_text.received: Acknowledgment that text was receivedconversation.item.audio_output.delta: Audio chunks as base64-encoded dataconversation.item.audio_output.done: Audio generation complete for an itemconversation.item.tts.failed: Error occurred
Text Processing:
- Partial text (no sentence ending) is held in buffer until:
- We believe that the text is complete enough to be processed for TTS generation
- The partial text exceeds
max_partial_lengthcharacters (default: 250) - The
input_text_buffer.commitevent is received
Audio Format:
- Format: Raw PCM (s16le, mono)
- Sample Rate: 24000 Hz
- Encoding: Base64 (per delta event)
- Delivered via
conversation.item.audio_output.deltaevents
Error Codes:
invalid_api_key: Invalid API key provided (401)missing_api_key: Authorization header missing (401)model_not_available: Invalid or unavailable model (400)- Invalid text format errors (400)
GET
Python WebSocket Client
Multi-context support
All client and server message types support an optionalcontext_id field. This allows you to manage multiple independent TTS streams over a single WebSocket connection.
Additional client message types
context.cancel: Cancel and clean up a specific context.
Additional server message types
context.cancelled: Confirms a context was cancelled.
Authorizations
Query Parameters
Response
101
Switching Protocols - WebSocket connection established successfully.
Error message format:
Python WebSocket Client