Lesson 27 / Unit 7: Adaptation and Serving
Streaming Synthesis
Piper ran at 19x real time on our CPU, yet we never measured when its first audio arrived. What streaming, sentence chunking and batching change, and how to time it.
Our timings stop when the whole waveform is ready. A caller waits for the first playable chunk. This lesson separates those measurements and shows where chunking belongs.
Incremental Audio
Streaming returns audio in pieces while synthesis continues, so a caller hears the first chunk before the last one exists. For a voice agent that turns the wait from “time to synthesise the whole reply” into “time to synthesise the first piece”.
Piper’s Python API already yields audio in chunks: voice.synthesize(text) is an iterator. Here is how we timed it in compare_piper.py:
t0 = time.perf_counter()chunks = list(voice.synthesize(text))el = time.perf_counter() - t0list() drains the iterator, so el is the time for every chunk. Divided by the audio duration, that gives the real-time factor we reported: whole-utterance throughput. It says nothing about time to first audio (TTFA), and we did not measure TTFA for any system. To time it, you would stop a clock at the first next() on the iterator instead, and repeat that under load. TTFA vs TTFB covers the definitions and why percentiles matter more than means.
Our own cascade shows where streaming effort should go. For the tiny model plus HiFi-GAN, the acoustic model took 3.6% of synthesis time and the vocoder the other 96.4%, at a whole-utterance real-time factor of 0.24. A streaming version of that pipeline lives or dies on how early the vocoder can start on the first frames of mel. HiFi-GAN is convolutional, so in principle it can decode a window of mel frames as they arrive, with some overlap to hide the seams; we did not build or measure that. What is a neural vocoder has the vocoder timings.
Sentence Chunking
Split the reply into sentences, synthesise the first one, and start playing it while the next ones are synthesised. As long as each chunk finishes before the previous one has played out, the caller hears continuous speech and waits only for the first sentence.
The caller waits for the first chunk only. Every later chunk has the playback time of the chunks before it to finish in.
Sustained throughput faster than playback is necessary, but an average RTF below 1 does not guarantee that every chunk meets its playback deadline. At 0.052, one second of Piper audio took about 52 ms to produce on our container; at 0.24, one second from our cascade took about 240 ms. Both leave headroom for one stream at a time, and both were measured at concurrency one, in our sequential timing loop.
Chunking has a cost at the boundaries. Each sentence synthesised alone loses the prosody that would have carried across from the one before. Short first chunks lower the wait but give the model less context to shape intonation.
Longform Context
NeMo’s Magpie-TTS longform documentation describes the same chunking idea built into the model’s inference. Longform mode activates at roughly 20 seconds of audio, with thresholds that differ by language:
| Language | Longform threshold (words) |
|---|---|
| English | 45 |
| German | 50 |
| Vietnamese | 50 |
| Italian | 53 |
| French | 69 |
| Spanish | 73 |
Text is split at sentence punctuation, with handling for abbreviations so “Dr. Smith” stays in one sentence. A LongformChunkState object carries history text tokens, encoder outputs and attention tracking from one sentence to the next, to support continuity across chunks. The generated codes are concatenated and decoded by the codec at the end. This longform path therefore does not, by itself, demonstrate low time to first audio. The docs recommend automatic mode detection, note that English is best supported, and say Mandarin currently falls back to standard inference.
The docs frame longform mode around prosodic continuity. We read it as touching a failure from the hallucinations lesson too: each decoding pass works on one sentence with tracked attention, rather than one pass over a whole passage in which an autoregressive model could skip or repeat.
Serving Tradeoffs
Batching can improve throughput while adding queueing delay. Quantisation can reduce memory and, with suitable kernels, compute time; it can also change quality. Both need measuring on your hardware, and we measured neither.
Batching matters most on a GPU. A GPU serving one request at a time leaves most of its capacity idle; grouping requests, or admitting new ones into a running batch as others finish, lets one forward pass serve many callers. The cost is that each request may wait for a batch to form and runs alongside others, so larger batches can raise p95 latency. Under heavy load, better throughput may instead reduce queueing; measure both effects. Pick the operating point deliberately, and measure real-time factor at your target concurrency. Our figures were taken one request at a time, by our sequential timing loop, and they are not a capacity number.
Quantisation stores weights at lower precision. Speech models can lose quality in ways a short listening test misses, because the damage tends to appear first on the hard inputs: numbers, long sentences, rare names. The check is the one you already built: run the fixed set through the eval harness and compare output WER against full precision. Also check where the time goes before you quantise. In our cascade, making the acoustic model twice as fast would save at most 1.8% of synthesis time (the split is in what is a neural vocoder).
Time the first chunk
Take any streaming TTS iterator, stop one clock at the first chunk and another at the last, and run it 50 times at your target concurrency. Report p50 and p95 for both. If you only have the second number, you have measured throughput, and your agent is waiting on the first.
Next: TTS cost and deployment, where the real-time factor becomes a cost per minute.
Common questions
What is streaming TTS?
Streaming TTS returns audio in chunks while the rest of the utterance is still being synthesised, so playback can start before synthesis finishes. What matters for a voice agent is the time to the first playable chunk, not the time to the whole utterance.
How does Magpie-TTS handle long text?
According to the NeMo documentation, Magpie-TTS switches to longform inference at roughly 20 seconds of audio, which is about 45 words in English. It splits the text into sentences, keeps state such as history text tokens and attention tracking across sentences for continuity, then concatenates the codes and decodes them with the codec.
Does quantising a TTS model reduce quality?
It can, and the damage tends to show up on hard inputs first. Measure it: run your fixed evaluation set through the quantised model and compare output WER and a listening check against the full-precision model before shipping.
We do this work for teams shipping voice agents: Self-Hosted Voice Agent .
Edit this lesson on GitHub ↗Discussion
Questions, corrections and war stories welcome. Sign in with GitHub to comment.