Design a Text-to-Speech Service
Understanding the Problem
🔊 What is a text-to-speech service? A text-to-speech (TTS) service turns written text into spoken audio that sounds like a person. Modern services offer a library of voices, let users create a voice from a recording of their own (voice cloning), stream audio back fast enough for live conversations, and control how things are said: emphasis, emotion, pace. ElevenLabs, OpenAI's and Google's speech APIs, and Amazon Polly are examples, and open models are close behind.
The question comes as "design ElevenLabs," "design a TTS API," or "how would you build voice cloning safely?" The two traffic types it serves have different needs, and a good design handles both. Real-time traffic (voice agents, games, reading an LLM's reply aloud) needs the first audio in a few hundred milliseconds and streams sentence by sentence. Long-form traffic (audiobooks, narration, video dubbing) cares about quality and consistency over hours of audio, and can wait. Voice cloning adds a trust and safety problem that belongs in the core design, not a footnote: a convincing clone of someone's voice is a fraud tool.
Functional Requirements
Core Requirements
- Users should be able to send text and a voice ID and receive natural speech, either streamed in chunks or as a finished file.
- Users should be able to clone a voice from their own recordings, after proving consent, and use it like any library voice.
- Users should be able to control delivery: pace, emphasis, emotion and pronunciation of specific words.
- Every generated clip should carry an inaudible watermark, and the platform should be able to tell whether a clip came from it.
Below the line (out of scope)
- Speech-to-speech voice conversion and dubbing pipelines (we'll mention where they fit).
- Speech recognition, covered in Design a Speech Recognition System.
- Music and sound effects generation.
Non-Functional Requirements
Ask what latency the real-time customers need, and how much audio is generated per day. Our numbers: 10 million minutes of audio a day across 30 languages. That's 10M ÷ 1,440 ≈ 6,900 streams at once on average, and about 20,000 concurrent streams at peak. About 60% of requests are real-time streaming; the rest are long-form jobs.
Core Requirements
- Time to first audio (request received to first audio byte) under 300 ms at p50 and 600 ms at p95 for streaming.
- Faster than real time: every stream must generate audio faster than it plays (a real-time factor below 1), or playback stutters.
- Quality: naturalness close to human recordings on mean opinion score tests, and correct pronunciation of names, numbers and dates.
- Safety: no voice clone without verified consent from the voice's owner; no clones of protected public figures.
- Availability of 99.9% for the streaming API, which voice agents depend on in live calls.
Below the line (out of scope)
- Studio-grade mastering of the output audio.
- Per-jurisdiction legal rules on voice rights in detail.
A few numbers that shape the design:
- One minute of speech is about 150 words, roughly 900 characters. 10M minutes is about 9 billion characters a day.
- Audio at 24 kHz, 16-bit mono is 48 KB per second raw. Streamed as Opus at ~32 kbps, 20,000 streams are about 640 Mbps of egress at peak. Bandwidth isn't the bottleneck; GPUs are.
- Suppose one GPU serves on the order of 50-100 real-time streams with batching (it depends heavily on model size and frame rate, as we'll see). 20,000 streams then need roughly 200-400 GPUs at peak, plus the long-form pool, which can run at high utilization off-peak.
The key tension: the best-sounding models are large and autoregressive, and the latency target is a few hundred milliseconds with every stream running faster than real time. Say early that model choice is constrained by both quality and time to first audio.