Skip to content

Neural vocoders: from WaveNet to DiffWave

A vocoder turns a spectrogram into a waveform. Four families do it: sample by sample (WaveNet, WaveRNN), invertible flows (WaveGlow), adversarial generators (MelGAN, HiFi-GAN, BigVGAN) and diffusion (DiffWave).

Advanced ~17 min11 steps

What runs in CodeSplash

You will be able to

  • Explain why rebuilding a waveform from a mel spectrogram needs a learned model
  • Describe autoregressive vocoders, their receptive field and why they are slow
  • Describe flow, adversarial and diffusion vocoders and their trade-offs
  • Explain why a small waveform error doesn't mean natural sound

Read first

01

What the mel spectrogram leaves out

Read

A mel spectrogram keeps the energy in a few dozen bands per frame and throws away the phase and the fine frequency detail. Many waveforms share one mel spectrogram, so turning it back into audio is a guess. A neural vocoderNeural vocoderA network that turns a spectrogram or other acoustic features into a waveform. It needs the exact mel settings it was trained on. learns to make that guess sound like real speech.

The vocoder only understands mel spectrograms made exactly as in its training: same rate, frame, hop, mel formula and log floor. A mismatch doesn't raise an error; it sounds wrong.

02

WaveNet: one sample at a time

Read

WaveNet predicts each sample from all earlier ones, p(x)=∏tp(xt∣x<t,c)p(x) = \prod_t p(x_t \mid x_{<t}, c), with cc the mel conditioning. The original squashes samples with μ-law compandingμ-law compandingA curve that maps audio samples to a few hundred levels with finer steps near zero, so a classifier can predict the next sample. into 256 levels and treats the next sample as a 256-way classification. To see far back cheaply it stacks causal dilated convolutionsCausal dilated convolutionA convolution that looks only back in time and skips inputs at growing gaps (1, 2, 4, …), so a short stack sees a long past., whose gaps double layer by layer, so the receptive field grows exponentially with depth.

On the reference's toy table, the categorical next-sample loss is 0.459. The quality was a leap, and so was the cost: 16,000 network passes for every second of 16 kHz audio.

Reference · AUD030 · Explained hereWaveNetAn autoregressive raw-waveform generator using causal dilated convolutions. It can model unconditional audio or act as a vocoder conditioned on acoustic features.
03

WaveRNN: smaller and split in two

Read

WaveRNN keeps sample-by-sample generation but makes each step cheap: a single compact recurrent layer, sparse weights and batched generation. It splits each 16-bit sample into a coarse and a fine byte, predicting the coarse one first and the fine one given it, p(xt)=p(at) p(bt∣at)p(x_t) = p(a_t)\,p(b_t \mid a_t), so each output is a 256-way choice instead of a 65,536-way one.

The reference's example adds the two cross-entropies: 1.703. WaveRNN made autoregressive vocoding feasible on phones, but it is still one step per sample.

Reference · AUD031 · Explained hereWaveRNNAn efficient autoregressive neural vocoder built around a compact recurrent network. The original design predicts high-resolution waveform samples through coarse/fine components and explores sparse and batched…
04

WaveGlow: invert a flow

Read

WaveGlow is a normalizing flowNormalizing flowA stack of invertible layers that turns each row into normal noise, so noise run backwards gives new rows and likelihoods are exact. conditioned on the mel spectrogram. Training maps real audio to Gaussian noise through invertible layers and maximizes the exact likelihood, noise density plus the log-determinant of the Jacobian. Generation runs the layers backward on fresh noise, all samples at once.

The reference's one-layer example, a fixed scale on 32 samples, gives a log density of −34.0. Parallel generation came at a size cost: flows need many large layers to be expressive.

Reference · AUD032 · Explained hereWaveGlowA flow-based conditional waveform generator converting Gaussian latents into audio conditioned on mel spectrograms.

Coupling layers and the change of variables, in two dimensions.

DExplorable · Normalizing flows: change of variables

Why does a normalizing flow need the log-determinant of its Jacobian?

Does the flow's density, as computed here, integrate to 1?

How sure?
3
0.50

How much each layer stretches: s(y) = α·tanh(u·y + v).

1.00

How much each layer bends: t(y) = β·sin(w·y) + c·y.

0.50
−0.50
Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

05

MelGAN and HiFi-GAN: adversarial vocoders

Read

MelGAN generates the waveform in one pass with transposed convolutions and trains it against discriminators that judge the audio at several time scales. A feature-matching lossFeature-matching lossA generator loss that matches a discriminator's inner-layer features on real and generated audio. It steadies adversarial training. compares the discriminators' inner layers on real and generated audio; in the reference's example it is 0.357.

HiFi-GAN adds multi-period discriminatorsMulti-period discriminatorDiscriminators that fold the waveform by a period (2, 3, 5, …) to judge repeating structure such as pitch (HiFi-GAN). that fold the waveform by periods such as 2, 3 and 5 to catch errors in repeating structure like pitch, plus a mel-spectrogram error. Its loss weights adversarial, feature and mel terms; with the reference's illustrative weights, 3.90. HiFi-GAN became the default vocoder: fast and close to real.

Reference · AUD033 · Explained hereMelGANA nonautoregressive waveform generator trained adversarially from mel spectrograms. Multi-scale waveform discriminators and intermediate feature matching encourage plausible local and longer-scale sound while avoiding… Reference · AUD034 · Explained hereHiFi-GANA high-fidelity adversarial vocoder using multiple generator receptive fields and discriminators that examine both periodic structure and multiple waveform scales.

Why adversarial training circles, and how a penalty settles it.

DExplorable · GAN dynamics: two players, collapse, gradient penalty

Why is GAN training unstable, and why does a GAN drop modes?

Where does training end up?

How sure?

View

Loss (two players)

Discriminator penalty

Updates

0.20
0.50

γ for R1, λ for WGAN-GP.

200

Generator trained by

Mode collapse view: a GAN with the best discriminator minimizes JS; reverse KL is the most mode-seeking; maximum likelihood minimizes KL(data‖model).

2.5

Modes at ±this value (mode collapse view).

1.5
  • Path of (θ, ψ)
  • Start
  • Equilibrium (0, 0)
  • Gradient field

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

06

BigVGAN: built to generalize

Read

BigVGAN targets voices, languages and recording conditions it never trained on. Its generator uses the Snake activationSnake activationx + sin²(ax)/a, with a learned. A periodic activation that helps a vocoder generator model repeating waveforms (BigVGAN)., x+sin⁡2(ax)/ax + \sin^2(ax)/a, which helps it model repeating waveforms, and filters around each nonlinearity to stop aliasing.

On a grid from −1 to 1 with a=2a = 2, the reference's example gives −0.587, −0.146, 0.0, 0.854 and 1.413: the identity line plus a wiggle that never goes negative.

Reference · AUD035 · Explained hereBigVGANA large neural vocoder designed for generalization across speakers and audio conditions. It combines adversarial training with periodic activations and anti-aliasing mechanisms, extending the neural-vocoder design…
07

DiffWave: denoise into audio

Read

DiffWave is a diffusion modelDiffusion modelLearns to reverse a gradual noising process, then generates by starting from pure noise and denoising in steps. on the waveform. Training adds Gaussian noise at a random level, xt=αˉt x0+1−αˉt ϵx_t = \sqrt{\bar\alpha_t}\,x_0 + \sqrt{1 - \bar\alpha_t}\,\epsilon, and teaches a network to predict the noise. Generation starts from noise and removes it step by step, with the mel spectrogram as the condition.

The reference's noise-prediction error is 0.0051. Quality rises with the number of steps, and so does the time: the classic diffusion trade-off.

Reference · AUD036 · Explained hereDiffWaveA diffusion model that generates waveform samples through iterative denoising, either unconditionally or conditioned on acoustic features.

The noising and sampling loop on a simple one-dimensional target.

DExplorable · Diffusion: noise schedule, sampler steps, guidance

How does a diffusion model turn noise back into data, and what do the schedule, the steps and guidance change?

With this sampler and number of steps, will the samples match the data?

How sure?

β schedule

250

The forward process at this step: how much signal is left.

Sampler

DDPM adds fresh noise every step; DDIM is deterministic.

50
0.0

0 = unconditional, 1 = plain conditional, above 1 = guided.

Class to guide toward

400
  • Noised samples
  • Exact q(xₜ)
  • Samples
  • Data

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

08

Choosing a vocoder

Predict

Predict first

A voice assistant must render speech faster than real time on a laptop CPU, with good quality on the voices it was trained on. Which vocoder family fits best?

WaveNetHiFi-GANDiffWave with many steps
Reveal

An adversarial vocoder such as HiFi-GAN: one parallel pass, with a real-time factorReal-time factorProcessing time divided by audio length: below 1 is faster than real time. Report it with the hardware and settings. far below 1 on a CPU. WaveNet runs one step per sample; diffusion with many steps runs the network many times.

09

Where it stands in CodeSplash

Read
EntryIn CodeSplash
WaveNet (AUD030)Explained here
WaveRNN (AUD031)Explained here
WaveGlow (AUD032)Explained here
MelGAN (AUD033)Explained here
HiFi-GAN (AUD034)Explained here
BigVGAN (AUD035)Explained here
DiffWave (AUD036)Explained here

CodeSplash doesn't generate audio. The seven reference programs are component checks, verified in Python and R.

10

Check: vocoders

Checkpoint

Check yourself

Four causal convolution layers with kernel size 2 have dilations 1, 2, 4 and 8. How many samples (the current one included) does the top output see?

Show the answer

Answer: 16

Each layer adds (k−1)×d(k-1) \times d samples: 1+1+2+4+8=161 + 1 + 2 + 4 + 8 = 16. Doubling the dilation each layer doubles the receptive field.

Check yourself

Why is generating audio with the original WaveNet slow?

Show the answer

Answer: b

At 16 kHz that is 16,000 sequential passes per second of audio. Training is parallel; generation isn't.

Check yourself

Why does WaveRNN split each 16-bit sample into a coarse and a fine byte?

Show the answer

Answer: a

The fine byte is predicted given the coarse one, keeping each softmax small.

Check yourself

What did WaveRNN keep from WaveNet, and what did it change?

Show the answer

Answer: b

Each step is cheap enough for phones, but generation is still sequential.

Check yourself

How does WaveGlow generate all samples at once?

Show the answer

Answer: b

Invertible layers map noise to audio in one pass. Training maximizes the exact likelihood through the same layers.

Check yourself

What is the main drawback of flow vocoders such as WaveGlow?

Show the answer

Answer: b

Invertibility restricts each layer, so expressiveness comes from stacking many of them.

Check yourself

What does MelGAN's feature-matching loss compare?

Show the answer

Answer: b

Matching intermediate features gives the generator a steadier signal than the real-or-fake verdict alone.

Check yourself

Why does MelGAN use discriminators at several time scales?

Show the answer

Answer: a

A coarse view checks long-range plausibility; fine views check local texture.

Check yourself

What do HiFi-GAN's multi-period discriminators look for?

Show the answer

Answer: c

Folding by periods such as 2, 3 and 5 lines up samples that repeat, so errors in pitch-like structure stand out.

Check yourself

HiFi-GAN adds a mel-spectrogram error to its adversarial losses. Why might it still sound bad on your TTS output?

Show the answer

Answer: b

A vocoder reads one mel convention. Rate, hop, mel formula and floor must all match its training.

Check yourself

Why does BigVGAN use the Snake activation x+sin⁡2(ax)/ax + \sin^2(ax)/a?

Show the answer

Answer: b

The learned frequency aa lets each channel favor a period; anti-aliasing filters keep the nonlinearity from adding false tones.

Check yourself

What was BigVGAN designed to do better than earlier GAN vocoders?

Show the answer

Answer: b

Scale, periodic activations and anti-aliasing target out-of-distribution audio.

Check yourself

What does DiffWave's network learn to predict during training?

Show the answer

Answer: b

Predicting the noise lets generation remove it step by step from pure noise.

Check yourself

You halve the number of DiffWave generation steps. What do you expect?

Show the answer

Answer: a

Each step is one network pass. Fewer steps trade quality for speed; measure both.

11

Recap

Recap
  • A mel spectrogram drops phase and detail; a vocoder learns a plausible waveform, for one mel convention.
  • WaveNet and WaveRNN generate sample by sample: good, slow.
  • WaveGlow inverts a flow; MelGAN, HiFi-GAN and BigVGAN generate in one adversarial pass; DiffWave denoises step by step.
  • A small waveform error doesn't mean natural sound. All are explained here.

Concepts in this lesson