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
Understanding TTS Methods
The SDK provides three methods for text-to-speech generation, each optimized for different use cases:Basic Usage
Generate speech from text with a single function call:Using Voice Models
Specify a voice model for consistent voice characteristics:Finding Voice Models
Get voice model IDs from the Fish Audio website or programmatically:Emotions and Expressions
Add emotional expressions to make speech more natural:Audio Formats
Choose the output format based on your needs:Prosody Control
Adjust speech speed and volume for natural-sounding output:TTSConfig with Prosody:
Reusable TTS Configuration
Create a configuration once and reuse it across multiple generations:Chunk-by-Chunk Streaming
Usestream() for memory-efficient transfer and progressive download. Chunks are network transmission units (not semantic audio segments):
Use
stream() when you have complete text upfront. For real-time streaming with dynamically generated text (LLMs, live captions), use stream_websocket() instead.Real-time WebSocket Streaming
For real-time applications where text is generated dynamically, usestream_websocket(). This is perfect for LLM integrations, conversational AI, and live captions:
Basic WebSocket Streaming
Understanding FlushEvent
The FlushEvent forces the TTS engine to immediately generate audio from the accumulated text buffer. This is useful when you want to ensure audio is generated at specific points, even if the buffer hasn’t reached the optimal chunk size.
TextEvent vs Plain Strings
You can yield plain strings (recommended for simplicity) or use TextEvent for explicit control:
LLM Integration Pattern
WebSocket streaming shines when integrating with LLM streaming responses. The TTS engine acts as an accumulator, buffering text until it has enough to generate natural-sounding audio:The WebSocket connection automatically buffers incoming text and generates audio when it has accumulated enough context for natural-sounding speech. You don’t need to manually batch tokens unless you want to force generation at specific points using
FlushEvent.Advanced Configuration
ComprehensiveTTSConfig with all available parameters:
Error Handling
Handle common TTS errors gracefully:RateLimitError, ValidationError, NotFoundError, and FishAudioError.
Best Practices
Chunk long text appropriately
Chunk long text appropriately
For long texts, adjust
chunk_length in TTSConfig:Cache frequently used audio
Cache frequently used audio
If you generate the same speech repeatedly, cache the results:
Handle rate limits gracefully
Handle rate limits gracefully
Implement exponential backoff for rate limits:
Use appropriate latency modes
Use appropriate latency modes
Balance speed vs quality based on your use case:
Next Steps
Voice Cloning
Create custom voice models
WebSocket Streaming
Real-time audio streaming
Fine-grained Control
Phoneme-level control and paralanguage
Best Practices
Production tips and optimization
Related Resources
- TTS API Reference - Complete API documentation
- Audio Formats Guide - Format comparison
- Emotion Reference - All available emotions
- Utils Reference - Audio utilities

