Prerequisites
Create a Fish Audio account
Create a Fish Audio account
Sign up for a free Fish Audio account to get started with our API.
- Go to fish.audio/auth/signup
- Fill in your details to create an account, complete steps to verify your account.
- Log in to your account and navigate to the API section
Get your API key
Get your API key
Once you have an account, you’ll need an API key to authenticate your requests.
- Log in to your Fish Audio Dashboard
- Navigate to the API Keys section
- Click “Create New Key” and give it a descriptive name, set a expiration if desired
- 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
Customize WebSocket behavior by configuring the client:Best Practices
- Chunk Size: Yield text in natural phrases for best prosody
- Buffer Management: Process audio chunks immediately to avoid memory buildup
- Connection Reuse: Keep WebSocket sessions alive for multiple streams
- Error Recovery: Implement retry logic for connection failures
- Format Selection: Use PCM for real-time playback, MP3 for storage
Events
The connection emits these events:| Event | Description |
|---|---|
OPEN | WebSocket connection established |
AUDIO_CHUNK | Audio chunk received (Uint8Array) |
ERROR | Error occurred on the connection |
CLOSE | Connection closed |

