Skip to main content
Streaming allows you to receive and play audio as it’s being generated, reducing perceived latency and enabling real-time applications.

Basic Streaming

Use the stream() method to get an iterator of audio chunks:

Stream Processing Options

You have two main ways to handle streamed audio:

Optimizing Streaming Latency

The optimize_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 optimization
  • 4 - Maximum + text normalizer off (lowest latency, may affect pronunciation)
Combine eleven_turbo_v2_5 or eleven_flash_v2_5 models with high optimization levels for the best streaming performance.

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:
The stream() function requires mpv to be installed. Install it with:
  • macOS: brew install mpv
  • Linux/Windows: Download from mpv.io

Best Practices

  • Use eleven_flash_v2_5 for the fastest streaming
  • Use eleven_turbo_v2_5 for balanced quality and speed
  • Avoid eleven_v3 for streaming if latency is critical
  • Lower sample rates (22050Hz) reduce latency
  • Lower bitrates (32kbps) improve streaming speed
  • Balance quality needs with performance requirements
For long streams, consider buffering to prevent memory issues:

Next Steps

Learn how to manage and customize voices