Skip to main content

Prerequisites

Sign up for a free Fish Audio account to get started with our API.
  1. Go to fish.audio/auth/signup
  2. Fill in your details to create an account, complete steps to verify your account.
  3. Log in to your account and navigate to the API section
Once you have an account, you’ll need an API key to authenticate your requests.
  1. Log in to your Fish Audio Dashboard
  2. Navigate to the API Keys section
  3. Click “Create New Key” and give it a descriptive name, set a expiration if desired
  4. Copy your key and store it securely
Keep your API key secret! Never commit it to version control or share it publicly.

Overview

WebSocket streaming enables real-time text-to-speech generation, perfect for conversational AI, live captioning, and streaming applications.

Basic Streaming

Stream text and receive audio in real-time:
Set text: "" in the request when streaming. The actual text comes from your text stream generator.

Using Voice Models

Stream with a specific voice:

Dynamic Text Generation

Stream text as it’s generated:

Line-by-Line Processing

Stream text line by line:

Errors

Handle connection errors via event listeners:

Configuration/Choosing Backend

Customize WebSocket behavior by configuring the client.
Optionally specify the backend model to use. Our state-of-the-art S1 model is the default:

Best Practices

  1. Chunk Size: Yield text in natural phrases for best prosody
  2. Buffer Management: Process audio chunks immediately to avoid memory buildup
  3. Connection Reuse: Keep WebSocket sessions alive for multiple streams
  4. Error Recovery: Implement retry logic for connection failures
  5. Format Selection: Use PCM for real-time playback, MP3 for storage

Events

The connection emits these events: