Speech Models
ASR chunked streaming (Whisper), TTS real-time factor, voice cloning pipelines — serving audio models at scale.
Speech inference spans two directions: speech-to-text (ASR) and text-to-speech (TTS). Each has unique latency requirements and serving patterns that differ from both LLM and diffusion serving.
1. ASR: Speech-to-Text
Whisper Architecture
Whisper is an encoder-decoder model:
Audio → Mel Spectrogram → Encoder (compute-heavy, one pass)
→ Decoder (autoregressive, like LLM decode)
→ Text tokens → Detokenize → Transcript
Encoder (1 pass): Processes 30 seconds of audio in ~0.5s on H100. Compute-bound, benefits from batching.
Decoder (autoregressive): Generates text tokens one at a time. Memory-bound like LLM decode, but much shorter sequences (100-300 tokens for 30s audio).
Chunked Streaming
For real-time transcription, audio is split into overlapping chunks:
Audio stream: [────────────────────────────────────]
Chunk 1: [═══════] → transcribe
Chunk 2: [═══════] → transcribe
Chunk 3: [═══════] → transcribe
↑ overlap ↑
Overlap ensures words at chunk boundaries aren’t missed. Typical: 30s chunks with 5s overlap.
Latency = chunk_duration + encode_time + decode_time. For streaming: user sees transcription ~1-2s after speaking.
Serving at Scale
| Optimization | Effect |
|---|---|
| Batch multiple audio streams | Encode in parallel (high throughput) |
| FP16 encoder | 2× faster encode |
| Speculative decoding for decoder | Faster text generation |
| Dedicated encoder + decoder pools | Encoder compute-heavy, decoder memory-heavy |
2. TTS: Text-to-Speech
Architecture Variants
| Architecture | How it works | Latency | Quality |
|---|---|---|---|
| Autoregressive (VALL-E style) | Generate audio tokens like LLM generates text | Higher (sequential) | High (natural prosody) |
| Non-autoregressive (VITS, FastSpeech) | Generate all frames in parallel | Lower (single pass) | Good (less natural) |
| Diffusion-based (Voicebox) | Iterative denoising on mel spectrograms | Medium (20-50 steps) | Very high |
| Hybrid (F5-TTS, CosyVoice) | Flow matching + vocoder | Medium | High |
Real-Time Factor (RTF)
RTF < 1 is required for real-time serving. RTF = 0.3 means generating 10s of audio takes 3s.
| Model | RTF (H100) | Streaming? |
|---|---|---|
| VITS | 0.05 | ✅ (non-AR, instant) |
| CosyVoice | 0.2-0.5 | ✅ (chunk-by-chunk) |
| VALL-E | 0.5-1.0 | ⚠️ (AR, depends on length) |
Voice Cloning Pipeline
Reference audio (3-10s) → Speaker encoder → Speaker embedding
Text prompt → TTS model (conditioned on embedding) → Generated audio
Serving consideration: Speaker embeddings can be cached — clone once, generate many times. The embedding is tiny (~256 floats) compared to the model.
3. Common Patterns for Audio Serving
| Pattern | Description |
|---|---|
| Streaming I/O | WebSocket for real-time audio streaming (both ASR and TTS) |
| Chunked processing | Process audio in fixed-size chunks for bounded latency |
| Vocoder sharing | Multiple TTS requests share the vocoder (mel → waveform is generic) |
| GPU/CPU split | Encoder/model on GPU, pre/post-processing on CPU |
Self-Check
- Explain Whisper’s encoder-decoder architecture and why the encoder is compute-bound
- Describe chunked streaming for real-time ASR
- Define RTF and calculate it for a given model
- Compare autoregressive vs non-autoregressive TTS for latency
- Design a voice cloning serving pipeline with cached speaker embeddings