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.
Get free API credits by verifying your phone number.
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 TTSRequest when streaming. The actual text comes from your text_stream generator.Using Voice Models
Stream with a specific voice:Real-Time Playback
Stream audio directly to speakers:Dynamic Text Generation
Stream text as it’s generated:Async WebSocket
For async applications:Integration Examples
ChatGPT Streaming
Stream ChatGPT responses to speech:Line-by-Line Processing
Stream text line by line:Error Handling
Handle connection errors:Configuration
Customize WebSocket behavior: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
Parameters
WebSocketSession
Parameter | Type | Description | Default |
---|---|---|---|
apikey | str | Your API key | Required |
base_url | str | API endpoint | ”https://api.fish.audio” |
max_workers | int | Thread pool size | 10 |
tts() Method
Parameter | Type | Description | Default |
---|---|---|---|
request | TTSRequest | TTS configuration | Required |
text_stream | Iterable[str] | Text generator | Required |
backend | str | Model version | ”speech-1.5” |