API DocsAI Model APIsAudioFish Audio

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:

  1. After connecting, send start once (with TTS config)
  2. Send text in chunks
  3. Optionally send flush to synthesize buffered text immediately
  4. 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):

NameTypeRequiredDescription
eventstringYesFixed to start
requestobjectYesTTS configuration; fields match HTTP TTS
request.textstringYesUsually an empty string in WebSocket mode
request.reference_idstring | string[] | nullNoVoice ID. A string for a single speaker; an array for multiple speakers
request.referencesobject[]NoInline reference audio (zero-shot cloning)
request.formatstringNoOutput format: wav, pcm, mp3, opus
request.latencystringNolow / normal / balanced
request.prosodyobjectNoSpeed and volume
request.temperaturenumberNoExpressiveness, [0, 1]. Default 0.7
request.top_pnumberNoNucleus sampling. Default 0.7
request.max_new_tokensintegerNoMaximum audio tokens per text chunk. Default 1024
request.min_chunk_lengthintegerNoMinimum characters before splitting a new chunk, [0, 100]. Default 50
request.chunk_lengthintegerNoText chunk length
request.normalizebooleanNoWhether to normalize Chinese/English text
request.sample_rateinteger | nullNoSample rate (Hz)
request.condition_on_previous_chunksbooleanNoWhether to use previous audio to keep the voice consistent

Subsequent client eventsobject

Text and control events.

textobject(Required, repeatable)
{ "event": "text", "text": "Hello! Welcome to Fish Audio." }

One event per text chunk. For multi-speaker, use <|speaker:0|> markers in the text.

flushobject(Optional)
{ "event": "flush" }

Force immediate synthesis of text still in the buffer.

stopobject(Required)
{ "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:

NameTypeDescription
eventstringaudio or finish
audiobinaryAudio chunk. Concatenate in arrival order
reasonstringFinish reason. stop is a normal end; error means a failure

Error Handling

Connection Failure / HTTP 401 / 403

  • 401 Unauthorized: API Key invalid or expired
  • 403 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.

On this page