
Connect to:
text
wss://api.teenage.works/v1/audio/speech/stream-input/{voice_id}The socket accepts pcm or mp3 through the response_format query parameter. output_sample_rate accepts 8000 through 48000 and defaults to 48000.
Send the bearer token in the connection headers. Browser clients that cannot set WebSocket headers can include api_key in the first message.
json
{
"text": " ",
"api_key": "tw_live_...",
"language_code": "en",
"quality": "fast",
"temperature": 1.0,
"seed": 1337,
"generation_config": {
"chunk_length_schedule": [120, 160, 250, 290]
},
"auto_mode": false
}The first text value is one space. A chunk schedule accepts up to eight integers; the server clamps each target to 20–1000 characters.
json
{
"text": "The next fragment of text.",
"flush": false,
"try_trigger_generation": false
}flush: true completes the current utterance.try_trigger_generation: true generates the pending buffer immediately.auto_mode: true generates after every text message.text value ends input, drains audio, and closes the socket.Audio messages contain a base64 chunk and an isFinal flag.
json
{
"audio": "<base64>",
"isFinal": false,
"normalizedAlignment": {
"chars": [],
"charStartTimesMs": [],
"charDurationsMs": []
}
}The final message is:
json
{"audio": null, "isFinal": true}Alignment arrays are compatibility placeholders and do not currently contain timestamps.
Socket errors use an error object before the connection closes or continues:
json
{"error":{"code":"invalid_text","message":"text must be a string"}}Common codes are invalid_api_key, invalid_request, invalid_text, text_too_long, and invalid_message.
On this page