Speech Synthesis
From vocoders to neural voices.
One sentence can be spoken in countless valid ways. Train a regressor to predict "the" acoustics of a text and it averages those ways into a flat, buzzy voice, which is why every stage of modern speech synthesis is a generative model. This lesson proves WaveNet's receptive field and counts its cost, derives the monotonic alignment search behind parallel synthesis, and analyzes the residual vector quantization that turns audio into tokens for codec language models.
What you’ll learn
- Explain the source–filter model, why spectrogram inversion needs phase, and why squared-error regression over-smooths a one-to-many mapping.
- Prove the causality and receptive field of dilated causal convolution stacks, and quantify the cost of autoregressive sampling and its remedies.
- Derive monotonic alignment search as a dynamic program, and compare attention-based and duration-based acoustic models.
- Analyze residual vector quantization (bitrate, capacity, successive refinement) and describe codec language models and how synthesis is evaluated.
One text, many voices
The source–filter model (Fant, 1960) describes speech as an excitation shaped by the vocal tract: periodic glottal pulses at a fundamental frequency for voiced sounds, or turbulent noise for unvoiced ones, filtered by resonances (formants) that depend on the tongue, lips and jaw. In frequency, , so in the log-spectrum the two add, which is what cepstral features exploit. Classical vocoders, from Dudley's 1939 vocoder to parametric systems that resynthesize speech from , a spectral envelope and aperiodicity, are built on this model.
A magnitude spectrogram drops the phase. Overlapping STFT frames constrain which phases are consistent, and Griffin & Lim (1984) recover a signal by alternating projections: impose the target magnitudes, invert, re-analyze, repeat. The result converges only to a local optimum and sounds metallic; the first Tacotron used it, and neural vocoders replaced it.
If half the recordings of a question end in a rising contour and half in a falling one, the optimal regressor predicts their average, which is nearly flat and matches neither. Fine spectral detail that varies from take to take is averaged into a smooth envelope: the muffled, buzzy sound of HMM-based statistical parametric synthesis (Zen, Tokuda & Black, 2009), which was flexible but over-smoothed. Unit selection (Hunt & Black, 1996) avoided averaging by concatenating recorded snippets chosen by Viterbi search over target and join costs; it sounded natural within units but glitched at the joins and could not say anything its database did not cover.
The remedy is to model the conditional distribution and sample from it, with the toolkit of Generative Models: autoregressive models, flows, VAEs, GANs and diffusion all appear below.
WaveNet: receptive fields and the price of autoregression
Claim: depends exactly on over the window , with . Layer reads layer at times , all non-negative offsets, so no future input ever enters (causality):
The oldest of these, , reaches back further by induction, so each layer extends the window by :
With and doubling dilations the sum is geometric. This is the stride-1 case of the receptive-field formula in Convolutional Networks in Depth.
Without dilation, a causal stack with kernel 2 sees only samples, so covering 1,024 samples would take 1,023 layers; dilation gives exponential reach with linear depth and parameters. WaveNet (van den Oord et al., 2016) adds gated activations (as in the gated PixelCNN), residual and skip connections, a 256-way softmax over μ-law levels, local conditioning on linguistic features or mel spectrograms upsampled to the sample rate, and global conditioning on speaker identity.
Cost. Training is parallel: the real waveform supplies every input. Sampling is sequential, one pass per sample, 24,000 passes for a second of 24 kHz audio. Caching each layer's past activations in queues (Fast WaveNet; Paine et al., 2016) makes each new sample cost layer updates instead of recomputing the receptive field, but the chain of sequential steps remains. Parallel WaveNet (van den Oord et al., 2018) distills the trained teacher into an inverse-autoregressive-flow student that generates all samples at once from noise, trained to minimize plus auxiliary losses; sparse WaveRNNs (Kalchbrenner et al., 2018) made sequential generation cheap enough for real-time synthesis on mobile CPUs.
A WaveNet vocoder at 16 kHz uses two blocks of ten layers with kernel size 2 and dilations . How much audio, in milliseconds, does each output sample's receptive field span?
Show the answer
128 ms
samples, and s. That is shorter than a typical syllable, so longer-range structure such as prosody must come from the conditioning features, not from the waveform model's own memory.
Alignment: attention versus durations
Tacotron 2 (Shen et al., 2018) encodes characters with convolutions and a BiLSTM, and an autoregressive LSTM decoder predicts 80-band mel frames (12.5 ms apart) plus a stop token, trained with squared error and refined by a convolutional post-net; a WaveNet conditioned on the mels produces the audio. Its location-sensitive attention (Chorowski et al., 2015) feeds the cumulative attention weights back through a convolution, encouraging the alignment to move forward. Nothing forces it to be monotonic and complete, though, and on long or unusual inputs attention-based TTS can skip words, repeat them, or fail to stop.
Duration-based models make the alignment explicit. Each input phoneme gets frames; a length regulator repeats encoder state times, and a decoder generates all frames in parallel. FastSpeech (Ren et al., 2019) took durations from a teacher model's attention; FastSpeech 2 (Ren et al., 2021) used forced alignment and also predicted pitch and energy, giving explicit prosody controls. Skipping and repeating become impossible by construction. Where do durations come from without an external aligner?
Let be the best score of aligning with frame on state . The objective is a sum over frames, and the previous frame sat either on the same state or on the one before:
Optimal substructure holds because any optimal alignment ending at restricts to an optimal alignment of ending at its predecessor. Fill the table, read , and backtrack:
Training alternates, as in hard (Viterbi) EM: with the parameters fixed, MAS finds ; with fixed, gradient steps raise the likelihood. The durations train a duration predictor used at synthesis time. It is the Viterbi algorithm on a left-to-right HMM with free transitions (HMM Algorithms).
Why does the MAS recursion need only the two predecessors and ?
- Because the latent frames are independent of one another
- Because each phoneme lasts at most two frames
- Because the alignment is monotonic and surjective: each new frame either stays on the current text state or advances by exactly one, never skipping a state
- Because attention weights sum to one
Show the answer
C. Because the alignment is monotonic and surjective: each new frame either stays on the current text state or advances by exactly one, never skipping a state
leaves exactly two possible predecessors of . Allowing skips would add and so on, but it would let text be dropped, the failure that alignment search is meant to prevent.
VITS (Kim, Kong & Son, 2021) went end to end: a conditional VAE whose prior is a normalizing flow, MAS for alignment, a stochastic duration predictor, and a HiFi-GAN-style decoder trained adversarially, mapping text to waveform in one parallel network.
Vocoders, codecs and codec language models
GAN vocoders generate waveforms in parallel. HiFi-GAN (Kong, Kim & Bae, 2020) upsamples mel frames to the sample rate with transposed convolutions (256 times for a 256-sample hop) and residual blocks of several receptive fields. Its multi-period discriminators reshape the 1-D waveform into 2-D with period , so each column holds samples apart and periodic structure becomes visible; multi-scale discriminators judge the raw and downsampled audio. The losses combine a least-squares adversarial term, feature matching on discriminator activations, and an L1 mel-spectrogram term. Diffusion vocoders (WaveGrad, DiffWave; both 2021) trade speed for quality with the number of steps.
SoundStream (Zeghidour et al., 2022) trains encoder, quantizer and decoder end to end with reconstruction, adversarial and feature-matching losses, and randomly drops trailing quantizers during training ("quantizer dropout") so one model serves several bitrates. EnCodec (Défossez et al., 2023) works the same way; its 24 kHz model emits 75 frames per second with codebooks of 1,024 entries, at 1.5, 3, 6, 12 or 24 kbit/s for 2, 4, 8, 16 or 32 codebooks, and a small transformer can compress the tokens further by entropy coding. With 8 codebooks, stored vectors index possible reconstructions per frame.
VALL-E (Wang et al., 2023) generates EnCodec tokens at 6 kbit/s (8 codebooks), conditioned on the phonemes and on the tokens of a 3-second recording of the target voice. An autoregressive transformer produces the first codebook frame by frame, 75 tokens per second; a non-autoregressive transformer then fills codebooks 2 to 8 for all frames in parallel, each given the coarser ones:
It was trained on the 60,000 hours of English audiobooks in LibriLight, transcribed automatically. Sampling, not beam search, decodes the autoregressive stage, since beam search could loop; VALL-E 2 (2024) added repetition-aware sampling. Later systems mix semantic tokens from self-supervised speech models with acoustic tokens, or replace token prediction by flow matching or diffusion over codec latents.
Key takeaways
- TTS is one-to-many: the squared-error optimum averages prosody and spectral detail into flat, buzzy speech, so every modern stage is generative. Magnitude spectrograms discard phase, which Griffin–Lim or a neural vocoder must supply.
- Dilated causal stacks are causal with receptive field , which is for kernel 2 and doubling dilations. WaveNet trains in parallel but samples one value at a time; caching, distillation into flows and compact RNNs cut the cost.
- Attention-based TTS (Tacotron 2) can skip or repeat; duration models (FastSpeech) make alignment explicit, and monotonic alignment search finds it as an Viterbi dynamic program, which VITS builds into an end-to-end model.
- GAN vocoders with multi-period and multi-scale discriminators generate in parallel. RVQ codecs spend bits per second and reach reconstructions from stored vectors, with graceful truncation to lower bitrates.
- Codec language models such as VALL-E generate the first codebook autoregressively and the rest in parallel, enabling voice imitation from seconds of audio; evaluation (MOS, recognizer WER, speaker similarity) and safeguards (consent, watermarking, detection) lag behind capability.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Half the recordings of a sentence end with a rising pitch contour and half with a falling one. What does a model trained with squared error on pitch contours predict for that sentence?
- A rising or a falling contour, chosen at random each time
- Whichever contour appeared in the most recent training batch
- Roughly the average of the two, a nearly flat ending that matches neither
- The falling contour, since declaratives are more common
Show the answer
C. Roughly the average of the two, a nearly flat ending that matches neither
The squared-error optimum is , the mean of the valid renditions. To produce one valid rendition the model must represent the distribution and sample from it, which is what autoregressive, flow, VAE, GAN and diffusion models do.
A causal convolution stack uses kernel size and dilations . What is its receptive field, in samples?
- 41
- 80
- 81
- 12
Show the answer
C. 81
. In general, dilations with kernel give , exponential in depth.
An RVQ codec uses 8 codebooks of 1,024 vectors each. How many vectors does it store, and how many distinct reconstructions can one frame take?
- 8,192 stored; up to reconstructions
- stored; reconstructions
- 1,024 stored; 8,192 reconstructions
- 8,192 stored; 8,192 reconstructions
Show the answer
A. 8,192 stored; up to reconstructions
Storage is vectors, but each frame picks one index per codebook, combinations. That is how residual quantization reaches fine resolution with small codebooks.
Which part of VALL-E's output is generated autoregressively, token by token?
- All 8 codebooks, 600 tokens per second of audio
- Only the first codebook, frame by frame; codebooks 2 to 8 are predicted in parallel given the coarser ones
- The mel spectrogram, frame by frame
- The phoneme sequence
Show the answer
B. Only the first codebook, frame by frame; codebooks 2 to 8 are predicted in parallel given the coarser ones
The first codebook carries the coarsest information and is modeled autoregressively at 75 tokens per second; a non-autoregressive model fills in each finer codebook for all frames at once. This keeps the sequential part short while keeping the fine detail conditioned on the coarse.
Further reading
- A. van den Oord, S. Dieleman, H. Zen, K. Simonyan, O. Vinyals, A. Graves, N. Kalchbrenner, A. Senior & K. Kavukcuoglu, "WaveNet: A generative model for raw audio," arXiv:1609.03499 (2016).
- J. Shen, R. Pang, R. J. Weiss et al., "Natural TTS synthesis by conditioning WaveNet on mel spectrogram predictions," ICASSP (2018).
- J. Kong, J. Kim & J. Bae, "HiFi-GAN: Generative adversarial networks for efficient and high fidelity speech synthesis," NeurIPS (2020).
- C. Wang, S. Chen, Y. Wu et al., "Neural codec language models are zero-shot text to speech synthesizers," arXiv:2301.02111 (2023).
- P. Taylor, Text-to-Speech Synthesis (Cambridge University Press, 2009).