WebSocket Streaming TTS
Bidirectional streaming TTS over WebSocket. The client pushes text chunks; the server pushes audio chunks.
Low-latency bidirectional speech synthesis over WebSocket. The client streams text; the server streams audio. Messages are serialized with MessagePack.
The request field inside StartEvent matches HTTP TTS parameters. In WebSocket mode, request.text is usually empty; actual text is sent in later TextEvents.
Base URL
wss://api.autorouter.top— Production
Authentication
BearerAuth: http (bearer)
Authenticate using a Bearer Token.
Format: Authorization: Bearer sk-xxxxxx
Endpoints
WSS /fishaudio/v1/tts/live
Real-time Speech Synthesis Channel
The connection may set the model request header: s1, s2-pro, s2.1-pro, s2.1-pro-free. If omitted or unrecognized, it falls back to s2.1-pro. For multi-speaker dialogue, use s2-pro or the S2.1-Pro series.
Client event order:
- After connecting, send
startonce (with TTS config) - Send
textin chunks - Optionally send
flushto synthesize buffered text immediately - After all text is sent, send
stop
Server events: Continuously return audio binary chunks, then send finish when done (reason is stop or error).
Request Body
Content-Type: application/msgpack
Start example:
{
"event": "start",
"request": {
"text": "",
"reference_id": "model-id",
"format": "opus",
"latency": "balanced"
}
}Properties (StartEvent):
| Name | Type | Required | Description |
|---|---|---|---|
event | string | Yes | Fixed to start |
request | object | Yes | TTS configuration; fields match HTTP TTS |
request. | string | Yes | Usually an empty string in WebSocket mode |
request. | string | string[] | null | No | Voice ID. A string for a single speaker; an array for multiple speakers |
request. | object[] | No | Inline reference audio (zero-shot cloning) |
request. | string | No | Output format: wav, pcm, mp3, opus |
request. | string | No | low / normal / balanced |
request. | object | No | Speed and volume |
request. | number | No | Expressiveness, [0, 1]. Default 0. |
request. | number | No | Nucleus sampling. Default 0. |
request. | integer | No | Maximum audio tokens per text chunk. Default 1024 |
request. | integer | No | Minimum characters before splitting a new chunk, [0, 100]. Default 50 |
request. | integer | No | Text chunk length |
request. | boolean | No | Whether to normalize Chinese/English text |
request. | integer | null | No | Sample rate (Hz) |
request. | boolean | No | Whether to use previous audio to keep the voice consistent |
Subsequent client eventsobject
Text and control events.
{ "event": "text", "text": "Hello! Welcome to Fish Audio." }One event per text chunk. For multi-speaker, use <|speaker:0|> markers in the text.
{ "event": "flush" }Force immediate synthesis of text still in the buffer.
{ "event": "stop" }Close the session after all text has been sent.
Responses
101: WebSocket established; MessagePack events follow
401: Unauthorized
Content-Type: application/json
Request Example
# WebSocket 无法用普通 curl 完整演示,请使用 wscat 或下方 SDK 示例
wscat -c "wss://api.autorouter.top/fishaudio/v1/tts/live" \
-H "Authorization: Bearer sk-xxxxxx" \
-H "model: s2.1-pro"Use MessagePack encoding and decoding in production, not JSON. The examples above only show event order.
Response Example
{
"event": "audio",
"audio": "<binary audio chunk>"
}Response fields:
| Name | Type | Description |
|---|---|---|
event | string | audio or finish |
audio | binary | Audio chunk. Concatenate in arrival order |
reason | string | Finish reason. stop is a normal end; error means a failure |
Error Handling
Connection Failure / HTTP 401 / 403
401 Unauthorized: API Key invalid or expired403 Forbidden: API Key has no access to this model (check token's model allowlist)
HTTP 402 Insufficient Balance
Returns insufficient user quota. Top up at the AutoRouter console.
finish.reason == error
The session failed during synthesis. Check the StartEvent configuration, voice ID, and text content, then reconnect.