Basic Streaming
Use thestream() method to get an iterator of audio chunks:
Stream Processing Options
You have two main ways to handle streamed audio:Optimizing Streaming Latency
Theoptimize_streaming_latency parameter trades some quality for lower latency:
int
0- Default (no optimizations)1- Normal (~50% latency reduction)2- Strong (~75% latency reduction)3- Maximum latency optimization4- Maximum + text normalizer off (lowest latency, may affect pronunciation)
Streaming with Output Formats
Specify the audio format for your stream:Lower sample rates and bitrates reduce bandwidth and improve streaming speed but decrease audio quality.
Collecting Streamed Audio
Save the entire audio while streaming:Custom Stream Handling
Implement custom logic for each audio chunk:Streaming with Timestamps
Get timing information while streaming:Async Streaming
Stream audio asynchronously for better concurrency:Playing Streamed Audio
The SDK provides multiple ways to play streamed audio:Best Practices
Choose the Right Model
Choose the Right Model
- Use
eleven_flash_v2_5for the fastest streaming - Use
eleven_turbo_v2_5for balanced quality and speed - Avoid
eleven_v3for streaming if latency is critical
Optimize Format
Optimize Format
- Lower sample rates (22050Hz) reduce latency
- Lower bitrates (32kbps) improve streaming speed
- Balance quality needs with performance requirements
Handle Errors Gracefully
Handle Errors Gracefully
Buffer Management
Buffer Management
For long streams, consider buffering to prevent memory issues:
Next Steps
Learn how to manage and customize voices