Foundations to Frontier
Tests
H. Generative Models › H2 Autoregressive Models

WaveNet (generative audio)

WaveNet (van den Oord et al., 2016) generates raw audio one sample at a time, 16000 or more per second. Each sample is a 256-way softmax over μ-law-companded values, conditioned on all earlier samples. Seeing far enough back with a convolutional network needs dilated causal convolutions. With kernel 2 and dilations 1, 2, 4, …, 512, ten layers cover 1024 samples, where undilated layers would need 1023. Gated activations, residual and skip connections, and global (speaker) and local (linguistic or mel-spectrogram) conditioning made it the first neural text-to-speech system to approach human naturalness. Sample-by-sample generation was too slow for products. Parallel WaveNet, WaveRNN, WaveGlow and HiFi-GAN followed, and today's speech generators predict neural-codec tokens with transformers. In the exercises you implement μ-law coding (36.6 dB vs 16.8 dB SNR on a quiet signal at 8 bits), dilated causal convolutions and receptive fields. You then train small gated WaveNets on synthetic periodic 'audio' with periods of 10–14 samples. With 4 layers, dilations 1, 2, 4, 8 (receptive field 16) beat dilation 1 everywhere (field 5): next-sample NLL 2.914 vs 3.107 nats. Five layers with a field of 32 reached 2.866.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Predicting sound one sample at a time

Digital audio is a long list of numbers, thousands per second. WaveNet treats it like text: it predicts the next number from all the previous ones, then appends its guess and repeats. To remember far enough back without a huge network, it stacks convolutions whose gaps double at every layer (1, 2, 4, 8, …), so a few layers see a long stretch of the past. The demo shows how quickly the receptive field grows with dilation compared with plain stacking.

Generative models lab
Kernel 2, 6 layers, dilations 1, 2, 4, 8, 16, 32: receptive field 64 samples (green, ending at the red sample). Doubling dilations grow it exponentially with depth.
Why engineers care

WaveNet-style vocoders made realistic synthetic speech possible; the same dilated causal convolutions model vibration, telemetry and other long sensor time series.

📝 Quick check (Level 0)
0/3 answered
  1. 1. WaveNet predicts…
  2. 2. Dilations in WaveNet…
  3. 3. WaveNet outputs a distribution over…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Model: p(x) = Π_t p(x_t | x_before t); each conditional is a 256-way softmax over 8-bit μ-law values F(x) = sign(x) ln(1 + μ|x|)/ln(1 + μ), μ = 255, which spends more levels on quiet sounds.
  • Dilated causal convolutions: kernel 2, output at t sees x[t] and x[t − d]; dilations 1, 2, …, 512 repeated in blocks; receptive field 1 + Σ d (1024 per block).
  • Layer: z = tanh(W_f ∗ x + V_f h) ⊙ σ(W_g ∗ x + V_g h); a 1×1 convolution feeds a residual connection to the next layer and a skip connection to the output head (ReLU, 1×1, softmax).
  • Conditioning: global (speaker embedding h added to every layer) and local (linguistic features or mel spectrograms, upsampled to the audio rate).
  • Results (2016): text-to-speech MOS 4.21 for US English vs 3.86 (concatenative) and 3.67 (parametric); Tacotron 2 (2018) with a WaveNet vocoder on mel spectrograms reached MOS 4.53, close to recorded speech (4.58).
  • Speed: generation is sequential (24000 steps for a second of 24 kHz audio). Parallel WaveNet (2018) distils into an inverse autoregressive flow; WaveRNN (2018) uses one small RNN; WaveGlow (2019, flow) and HiFi-GAN (2020, GAN) are parallel.
  • Today (2026): neural audio codecs (SoundStream 2021, EnCodec 2022) turn audio into discrete tokens at about 50–75 frames per second; transformers predict those tokens autoregressively (AudioLM 2022, VALL-E 2023) or with flow matching, and the codec decoder replaces the vocoder.
📝 Quick check (Level 1)
0/3 answered
  1. 1. μ-law companding gives more levels to…
  2. 2. Skip connections in WaveNet go to…
  3. 3. Parallel WaveNet uses…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

μ-law, dilation and causality

Exercise 1.

  • μ-law encode and decode, and compare quantisation SNR with linear coding.
  • A kernel-2 dilated causal convolution.
  • The receptive field of a dilation schedule.

Practice.

  • Pad on the left only (causal padding) or shift outputs; check that output t never depends on input t + 1.
  • Use blocks of dilations 1..512 repeated 2–4 times; gated units, residual and skip connections.
  • Train with teacher forcing on random audio crops longer than the receptive field; score only positions with full context.
  • For speech synthesis today, use a pretrained codec and a token model, or a fast vocoder (HiFi-GAN, BigVGAN, Vocos) on mel spectrograms.
  • Generate with caching of each layer’s past activations (fast WaveNet generation, 2016).
import torch, torch.nn as nn
class Block(nn.Module):
    def __init__(s, C, d):
        super().__init__(); s.d = d; s.conv = nn.Conv1d(C, 2 * C, 2, dilation=d); s.res = nn.Conv1d(C, C, 1); s.skip = nn.Conv1d(C, C, 1)
    def forward(s, h):
        a = s.conv(nn.functional.pad(h, (s.d, 0)))          # causal: pad on the left only
        z = torch.tanh(a[:, :a.shape[1] // 2]) * torch.sigmoid(a[:, a.shape[1] // 2:])
        return h + s.res(z), s.skip(z)
blocks = nn.ModuleList(Block(64, 2 ** i) for _ in range(3) for i in range(10))   # field 3070 samples
🐍 Exercise 1: μ-law, dilation and receptive fields
Implement μ-law coding, a dilated causal convolution and the receptive-field formula, and compare μ-law with linear quantisation.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Causal padding pads…
  2. 2. Score training loss only where…
  3. 3. Fast vocoders today include…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Receptive field. A stack of kernel-k causal convolutions with dilations d₁..d_L sees 1 + (k − 1) Σ dᵢ samples. With doubling dilations the field is 2^L for k = 2, exponential in depth at constant cost per layer; without dilation it is L + 1. Ten layers: 1024 vs 11 samples.

Why μ-law. Speech amplitudes are roughly Laplacian with most samples small. Uniform 8-bit steps are 1/128 of full scale, coarse for quiet passages; μ-law spends levels logarithmically so that relative error is roughly constant, close to 14-bit linear quality in 8 bits (ITU-T G.711, 1972).

Why a softmax. A categorical output makes no shape assumption and can represent multimodal next-sample distributions (for example at onsets); van den Oord et al. found it worked better than mixture models.

Cost of generation. Each sample needs a forward pass; with cached activations each pass costs O(L) for L layers instead of recomputing the receptive field, but the T steps remain sequential.

system year parallel generation idea
WaveNet 2016 no dilated causal convolutions
Parallel WaveNet 2018 yes distillation into an IAF
WaveRNN 2018 no (but fast) one small RNN, sparsity
WaveGlow 2019 yes normalizing flow
HiFi-GAN 2020 yes GAN vocoder
VALL-E 2023 over codec tokens AR transformer on EnCodec tokens
📝 Quick check (Level 3)
0/3 answered
  1. 1. Receptive field of kernel 2, dilations 1..512:
  2. 2. μ-law gives roughly constant…
  3. 3. Generation with caching still needs…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How much does a longer receptive field, obtained by dilation at the same depth, improve next-sample prediction of periodic audio?

History.

  • A. van den Oord et al., “WaveNet: a generative model for raw audio” (2016).
  • J. Shen et al., “Natural TTS synthesis by conditioning WaveNet on mel spectrogram predictions” (Tacotron 2, 2018); A. van den Oord et al., “Parallel WaveNet” (2018).
  • N. Kalchbrenner et al., “Efficient neural audio synthesis” (WaveRNN, 2018); J. Kong et al., “HiFi-GAN” (2020).
  • Z. Borsos et al., “AudioLM” (2022); C. Wang et al., “Neural codec language models are zero-shot text to speech synthesizers” (VALL-E, 2023).

Exercise 2. Synthetic “audio”: each sequence repeats a random smoothed waveform with a period of 10 to 14 samples, random amplitude and phase, plus noise of std 0.03; μ-law quantised to 32 levels; 400 training and 200 test sequences of 64 samples.

  • Model: scalar input embedded to 12 channels; per layer a kernel-2 dilated causal convolution to 24 channels, tanh ⊙ σ gate, 1×1 residual; ReLU and a 32-way softmax.
  • Variants: 4 layers with dilations 1, 1, 1, 1 (field 5); 4 layers with 1, 2, 4, 8 (field 16, same parameters); 5 layers with 1..16 (field 32).
  • Training: 200 Adam steps, batch 8, lr 0.02; backpropagation written by hand (checked by finite differences). NLL is scored on the last 32 samples, where every model has full context.
model receptive field test NLL (nats/sample)
uniform guess – 3.466
noise floor (clean waveform known) – 1.119
4 layers, no dilation 5 3.107
4 layers, dilations 1, 2, 4, 8 16 2.914
5 layers, dilations 1..16 32 2.866
  • Dilation helped at equal cost: the same 4 layers and parameters gained 0.19 nats per sample once the field (16) covered a whole period (10–14), so the model could look up the matching point one cycle back.
  • Two periods of context helped a little more (2.866), by averaging the noise across cycles.
  • Seeds 1 and 2: field 5: 3.106 and 3.094; field 16: 2.977 and 2.932; field 32: 2.842 and 2.796.
  • Far from the floor: if the clean waveform were known, the quantised noise alone would cost 1.119 nats per sample (1.060 and 1.091 on seeds 1 and 2); after 200 steps every model is far from that, so the ranking, not the level, is the result.
🐍 Exercise 2 (research): how much does a longer receptive field, obtained by dilation at the same depth, improve next-sample prediction of periodic audio?
Train small gated WaveNets with and without dilation on synthetic periodic audio and compare next-sample likelihood against their receptive fields.

WaveNet in AI, robotics and aerospace

  • Speech interfaces: cockpit and robot voice assistants use neural vocoders or codec-token models descended from WaveNet.
  • Sensor time series: dilated causal convolutions (TCNs) forecast and detect anomalies in vibration, telemetry and power data.
  • Compression: neural audio codecs (SoundStream, EnCodec) compress speech and sound for low-bandwidth links.

References

  1. A. van den Oord et al. (2016). “WaveNet: a generative model for raw audio.” arXiv:1609.03499.
  2. A. van den Oord et al. (2018). “Parallel WaveNet: fast high-fidelity speech synthesis.” ICML.
  3. J. Shen et al. (2018). “Natural TTS synthesis by conditioning WaveNet on mel spectrogram predictions.” ICASSP.
  4. N. Kalchbrenner et al. (2018). “Efficient neural audio synthesis.” ICML.
  5. J. Kong, J. Kim and J. Bae (2020). “HiFi-GAN: generative adversarial networks for efficient and high fidelity speech synthesis.” NeurIPS.