Text-to-Speech › Neural Vocoders
Language AI HandbookAll chapters Text-to-Speech › Neural VocodersOne section · Sections in this chapter5 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The mel-spectrogram gives a compact, perceptually relevant representation, but it discards phase information. Reconstructing a waveform requires estimating these missing phases, a problem classical signal processing solves through iterative algorithms that often produce metallic artifacts or temporal smearing. Neural vocoders learn to generate waveforms directly, conditioned on spectrograms, creating materially more natural speech with crisp transients and appropriate noise characteristics.
Autoregressive Vocoders: WaveNet and WaveRNN
WaveNet, developed by DeepMind, pioneered autoregressive neural vocoding. Operating directly on the raw audio waveform, WaveNet models the joint probability of audio samples as a product of conditional probabilities:
where:
- : the joint probability of the audio waveform consisting of samples
- : the total number of audio samples in the waveform
- : the current time step index (from 1 to )
- : the audio sample at time step
- : all previous audio samples before time
- : the conditioning information (the mel-spectrogram)
- : the conditional probability of sample given previous samples and conditioning
This mirrors the autoregressive language modeling we discussed in Part XXII: Causal Language Modeling, but applied to continuous audio samples rather than discrete tokens. The model learns the statistical dependencies between consecutive samples. This keeps the generated waveform is locally consistent and free of discontinuities.
WaveNet uses dilated causal convolutions, which are convolutions with gaps (dilations) that exponentially increase the receptive field while maintaining causality (no access to future samples). A stack of dilated convolutions with dilation rates allows the model to capture temporal dependencies across thousands of samples (hundreds of milliseconds) using relatively few layers. The causal constraint ensures that the prediction for sample depends only on samples through , preserving the autoregressive property and preventing the model from "cheating" by looking at future values during training.
The model outputs a categorical distribution over quantized audio amplitudes (typically 8-bit or 16-bit -law encoded), sampled autoregressively to generate waveforms. While WaveNet produces excellent quality with rich timbre and natural-sounding speech, its sample-by-sample generation is computationally prohibitive for real-time applications, often requiring specialized hardware like GPUs or TPUs to reach acceptable speeds.
WaveRNN addresses this by using a single-layer recurrent network with dual softmax outputs for coarse and fine quantization levels, reducing computational complexity while maintaining quality. The dual softmax splits the prediction of 16-bit audio into two 8-bit predictions (coarse and fine), simplifying the probability distribution. However, both models remain slower than real-time without specialized hardware acceleration, limiting their deployment in resource-constrained environments.



GAN-Based Vocoders
Generative Adversarial Networks give an alternative path to fast, high-quality vocoding. Rather than modeling the exact likelihood of each audio sample, which requires expensive autoregressive computation, GAN vocoders learn to produce waveforms that are indistinguishable from real speech according to a discriminator network. This adversarial approach trades exact probabilistic modeling for speed and perceptual quality.
MelGAN and HiFi-GAN stand for the state of the art in efficient neural vocoding. These models use transposed convolutions to upsample mel-spectrograms to audio rates, followed by residual blocks with dilated convolutions to model temporal dependencies. The generator operates non-autoregressively, creating audio frames in parallel, which lets real-time synthesis on standard hardware.
Training employs multiple discriminators operating at different time scales:
- A multi-scale discriminator examines the waveform at different resolutions (raw audio, average-pooled by 2, by 4), capturing structure at various temporal granularities
- A multi-period discriminator examines different periodic patterns (every 2nd sample, every 3rd sample, etc.), capturing pitch periodicity and harmonic structure that are important for natural-sounding speech
The adversarial loss encourages the generator to match the distribution of natural speech:
where:
- : the adversarial loss function training the generator to fool the discriminator
- : the expectation over real audio and corresponding spectrogram pairs from the training data
- : real audio waveform sampled from the data distribution
- : the input mel-spectrogram used as conditioning for generation
- : the discriminator network that classifies audio as real (1) or fake (0)
- : the generator network (vocoder) that synthesizes audio from spectrograms
- : the expectation over generated samples produced from spectrogram
Additional feature matching losses (L1 distance between intermediate discriminator layer activations for real vs. generated audio) and mel-spectrogram reconstruction losses stabilize training and ensure that the generated audio remains faithful to the conditioning spectrogram, preventing mode collapse where the generator produces plausible-sounding audio that does not match the input text.
HiFi-GAN reaches real-time synthesis on CPUs while matching WaveNet quality by using a multi-receptive field fusion (MRF) module that processes audio through parallel dilated convolution branches with different dilation rates, similar to the Inception architecture in computer vision. This allows the model to capture both short-term transients (like consonant bursts) and long-term structure (like pitch periodicity) simultaneously.

Flow-Based and Diffusion Vocoders
Flow-based models like WaveGlow and WaveFlow give an alternative to adversarial training, learning an invertible transformation between a simple noise distribution and the complex distribution of audio waveforms. These models allow exact likelihood computation and efficient sampling through the change of variables formula. Given an invertible function that turns a latent noise vector into an audio sample , the log-likelihood of is:
where:
- : the log-likelihood of the audio waveform under the model
- : the log-likelihood of the latent variable under the base distribution (typically a standard Gaussian)
- : the learned invertible transformation mapping from latent space to data space
- : the latent noise variable drawn from a simple base distribution
- : the Jacobian matrix of partial derivatives of with respect to
- : the determinant of the Jacobian, accounting for the volume change under the transformation
The Jacobian determinant term is what makes normalizing flows computationally tractable. For a general invertible function, computing this determinant requires operations for -dimensional data, which makes it prohibitive for raw audio. Flow models avoid this by constructing as a composition of simple bijections with triangular or block-diagonal Jacobians, for which the determinant reduces to a product of diagonal elements. WaveGlow uses affine coupling layers where each layer splits the input into two halves, uses one half to predict scale and shift parameters applied to the other half, and the resulting Jacobian is triangular by construction.
Flow-based vocoders train stably and allow exact likelihood evaluation, which is useful for model selection and debugging. They avoid the training instabilities associated with GAN discriminators and the exposure bias of autoregressive models. However, they historically lagged GANs in perceptual quality, though recent architectures have narrowed this gap through improved coupling layers and conditioning mechanisms that incorporate the mel-spectrogram more deeply into each transformation stage.
Diffusion-based vocoders stand for the most recent advancement in this space. Models like DiffWave and WaveGrad treat waveform generation as a denoising problem: starting from Gaussian noise, the model iteratively refines the signal over diffusion steps, each step guided by the mel-spectrogram conditioning. At each step , the model predicts the noise component that was added to the clean signal at that diffusion level, and subtracts an estimate of this noise to take one step toward the clean waveform. Because the model learns a smooth denoising function rather than a single direct mapping, diffusion models can capture complex multimodal distributions in the audio space, creating outputs with rich textural detail. The primary limitation is inference speed: achieving high quality typically requires 50 to 200 diffusion steps, each of which involves a full neural network forward pass. Recent work has focused on distilling diffusion models into fewer steps, using progressive distillation techniques that teach a student model to jump over multiple original steps in a single stride, achieving real-time performance with as few as 4 to 6 inference steps.