{
"event": "start",
"request": {
"text": "",
"format": "mp3",
"chunk_length": 300,
"reference_id": "9a9cf47702da476aa4629e2506d4a857",
"latency": "normal"
}
}{
"event": "text",
"text": "Hello, this is streaming text. "
}{
"event": "flush"
}{
"event": "stop"
}{
"event": "audio",
"audio": "<binary audio data>"
}{
"event": "finish",
"reason": "stop"
}{
"event": "error",
"error": "Reference not found"
}WebSocket TTS Streaming
Real-time text-to-speech streaming via WebSocket
request payload inside StartEvent uses the same parameters as the HTTP Text to Speech API. For more detailed field guidance, model-specific behavior, and examples, see that page. In WebSocket mode, request.text is typically empty in StartEvent, and the text content is sent through subsequent TextEvent messages.sk-fish- API key, mint a single-use ek-fish- token with tts:write and pass ["bearer", token] as the WebSocket subprotocol. Because browser WebSocket connections cannot send custom headers like model, browser-direct sessions use the default model (s2.1-pro); relay through your server or use HTTP fetch with CORS when you need a specific model header. See Ephemeral Tokens for Browsers and Client Apps.{
"event": "start",
"request": {
"text": "",
"format": "mp3",
"chunk_length": 300,
"reference_id": "9a9cf47702da476aa4629e2506d4a857",
"latency": "normal"
}
}{
"event": "text",
"text": "Hello, this is streaming text. "
}{
"event": "flush"
}{
"event": "stop"
}{
"event": "audio",
"audio": "<binary audio data>"
}{
"event": "finish",
"reason": "stop"
}{
"event": "error",
"error": "Reference not found"
}API key authentication using Bearer token.
Get your API key from https://fish.audio/app/api-keys
Pass the token in the Authorization header:
Authorization: Bearer YOUR_API_KEY
TTS model to use for this session. If omitted or set to an unrecognized value, the session falls back to s2.1-pro. Use s3-pro, s3-pro-free, an S2.1-Pro model, or s2-pro for multi-speaker dialogue synthesis. s1 is deprecated and will be retired on December 31, 2026. After that date, requests that specify s1 are served by s3-pro.
s1, s2-pro, s2.1-pro, drama-3, s3-pro, s3-pro-freeInitiates a TTS streaming session with configuration.
This must be the first message sent after connecting. It contains all the configuration for voice, audio format, and generation parameters.
The request payload uses the same fields as the HTTP TTS API. In
WebSocket mode, request.text is typically empty in the StartEvent and
the actual text is streamed through subsequent TextEvent messages.
For full parameter details, examples, and model-specific guidance, see the HTTP Text to Speech API.
Sends a chunk of text for synthesis.
You can send multiple TextEvent messages in sequence. The server will buffer and synthesize text according to the chunk_length parameter from StartEvent.
Forces immediate synthesis of all buffered text.
Use this when you want audio generated immediately without waiting for more text or for the buffer to fill up. Useful for ensuring low latency in interactive applications.
Signals the end of the text stream.
After sending this event, the server will finish synthesizing any remaining buffered text and send a FinishEvent. The connection stays open.
Contains generated audio bytes.
You will receive multiple AudioEvent messages as audio is generated. Each message contains a chunk of audio in the format you specified. Concatenate all chunks to get the complete audio.
Signals that the TTS session has completed.
- If reason='stop', synthesis completed successfully
- If reason='error', an error occurred (client should handle gracefully)
After a session that completed (reason='stop'), the WebSocket connection stays open. To run another session, send a new StartEvent on it. When you no longer need the connection, close it with code 1000. An open connection between sessions does not count against your concurrency limit.
Reports a request-level failure. After an invalid StartEvent, a missing voice reference, or another error in what you sent, the session ends but the socket stays open, so you can send another StartEvent. After a concurrency refusal the socket closes, and a server-side failure can close it too.
Was this page helpful?

