Foundations to Frontier
Tests
E. Deep Learning › E11 Recurrent and Sequence Models

WaveNet

WaveNet (van den Oord and colleagues, DeepMind, 2016) generates raw audio one sample at a time, 16,000 samples per second, with a deep stack of dilated causal convolutions. Gated activations, residual and skip connections, and a 256-way softmax over μ-law-quantised samples complete the design. Conditioned on text features, it produced far more natural speech than previous synthesisers, and with distillation (Parallel WaveNet) it went into production. This page covers the architecture, μ-law quantisation, conditioning and the cost of autoregressive generation. In the exercises you implement gated units, receptive fields and μ-law companding, then show why WaveNet uses μ-law: over a 100-fold range of loudness, 8-bit μ-law keeps SNR between 31 and 38 dB, while 8-bit linear levels fall to −0.4 dB on quiet audio.

Level 0: Foundation

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

Writing sound one sample at a time

Digital audio is a long list of numbers, thousands per second. WaveNet predicts the next number from all the recent ones, picks one, appends it and repeats. To hear far enough back, it stacks convolutions that look 1, 2, 4, … 512 samples apart. To make prediction a choice among a manageable number of options, it squashes each sample into one of 256 levels, spaced finely for quiet sounds and coarsely for loud ones. The demo shows how dilations extend the reach.

Sequence-model lab
Receptive field 16 inputs with 4 layers of kernel 2 (dilations double each layer: 2^L).
Why engineers care

Neural vocoders descended from WaveNet produce the voices of assistants and navigation systems. The same dilated-convolution idea models vibration and acoustic sensor signals.

📝 Quick check (Level 0)
0/3 answered
  1. 1. WaveNet generates audio…
  2. 2. Each sample is chosen among…
  3. 3. Its long reach comes from…

Level 1: Beginner

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

By hand

  • Model: p(x) = Πₜ p(xₜ | x₁ … xₜ₋₁), with each factor a 256-way softmax.
  • Dilated stack:
    • dilations 1, 2, …, 512 (10 layers, kernel 2), repeated in several stacks;
    • one stack plus the initial causal convolution sees 1025 samples, and three stacks see 3071;
    • at 16 kHz, 3071 samples is 192 ms.
  • Gated activation: z = tanh(W_f ∗ x) ⊙ σ(W_g ∗ x), as in PixelCNN. With filter 0 the output is 0 whatever the gate; with gate 0 it is half the filter’s tanh.
  • Residual and skip connections: each layer’s output adds to its input (residual) and is also sent to the output head (skip). The skips are summed, then passed through ReLU, 1 × 1 convolutions and a softmax.
  • μ-law companding:
    • f(x) = sign(x) ln(1 + μ|x|)/ln(1 + μ) with μ = 255, then 256 uniform levels;
    • f(0.01) = 0.228, so quiet samples get many levels;
    • near zero, μ-law levels are 1.7 × 10⁻⁴ apart, against 7.8 × 10⁻³ for linear 8-bit (45 times finer);
    • modelling 16-bit audio directly would need a 65,536-way softmax.
  • Generation cost: one network evaluation per sample, 16,000 per second of audio. The original model was far slower than real time.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Receptive field of one stack (1–512, k = 2) plus the first convolution:
  2. 2. μ-law value of 0.01:
  3. 3. Network evaluations to generate 1 s at 16 kHz:

Level 2: Intermediate

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

WaveNet in code

Exercise 1.

  • The gated unit behaved as expected.
  • Receptive fields came out at 1025 and 3071.
  • μ-law companding inverted exactly on a grid of 11 values.

Practice.

  • Training is parallel: all samples’ predictions are computed at once by the causal convolutions (teacher forcing).
  • Generation is sequential. Cache each layer’s recent activations (Fast WaveNet, Paine et al., 2016) so a new sample costs one step per layer instead of recomputing the whole field.
  • Conditioning:
    • global conditioning (speaker identity) adds a learned bias to every gate;
    • local conditioning (linguistic or mel-spectrogram features) is upsampled to the audio rate and added per time step.
  • Parallel WaveNet (van den Oord et al., 2018) distils the autoregressive teacher into a flow-based student that generates all samples in parallel, over 20 times faster than real time.
def gated_layer(x, cond, d):
    h = dil_conv_f(x, d) + cond_f(cond); g = dil_conv_g(x, d) + cond_g(cond)
    z = torch.tanh(h) * torch.sigmoid(g)
    return x + res_1x1(z), skip_1x1(z)          # residual output, skip output
🐍 Exercise 1: WaveNet building blocks
Implement the gated activation, WaveNet's receptive field and μ-law companding with its inverse.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Training WaveNet is…
  2. 2. Speaker identity is a form of…
  3. 3. Parallel WaveNet uses…

Level 3: Advanced

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

Theory

Why model a waveform autoregressively. The chain rule factorises any joint distribution exactly. A categorical output can represent multimodal per-sample distributions (silence or loud, for example) that a Gaussian output would average away.

Why μ-law.

  • Speech amplitudes are concentrated near zero with a heavy tail, roughly Laplacian, and loudness varies widely.
  • Uniform levels waste resolution on rare loud values and starve quiet ones.
  • μ-law spacing grows with amplitude, so the relative error stays roughly constant. The signal-to-noise ratio is then nearly independent of loudness, which is the property of a good logarithmic quantiser, as in telephone codecs (ITU G.711).

Gating and residuals. Multiplicative gates let each unit switch its contribution on or off depending on context, which worked better than ReLU in PixelCNN and WaveNet. Residual and skip connections make a 30-layer stack trainable, and give the output direct access to every scale.

Cost. Autoregressive sampling is inherently sequential. This drove research into caching, distillation and non-autoregressive vocoders (WaveGlow, HiFi-GAN).

📝 Quick check (Level 3)
0/3 answered
  1. 1. A categorical output can represent…
  2. 2. μ-law keeps roughly constant…
  3. 3. Telephone μ-law codec standard:

Level 4: Expert

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

Why quantise with μ-law?

History.

  • μ-law companding has been standard in North American and Japanese telephony since the 1960s–70s (ITU G.711, 1972).
  • A. van den Oord, S. Dieleman, H. Zen, K. Simonyan, O. Vinyals, A. Graves, N. Kalchbrenner, A. Senior and K. Kavukcuoglu introduced WaveNet (2016).
  • Parallel WaveNet (2018) made it practical for production speech synthesis.

Exercise 2.

  • Signals: speech-like test signals (Laplacian samples with a slow loudness envelope, 16,000 samples) at loudness from 0.01 to 1 of full scale.
  • Quantisers: each signal is quantised to 256 levels, linearly or with μ-law (μ = 255).
  • Measurement: signal-to-noise ratio.
loudness 256 linear levels 256 μ-law levels
0.01 −0.4 dB 31.0 dB
0.03 10.3 dB 35.3 dB
0.1 21.4 dB 37.1 dB
0.3 30.9 dB 37.7 dB
1.0 41.0 dB 38.4 dB
  • μ-law is nearly loudness-independent: 31–38 dB over a 100-fold range.
  • Linear levels collapse on quiet audio. At 1% of full scale, the noise is as loud as the signal: the nearest levels to zero are ±0.004, coarser than the signal itself.
  • Linear wins only at full scale (41 against 38 dB). Real speech spends most of its time well below full scale, so μ-law is the better 8-bit choice, and it keeps WaveNet’s softmax at 256 classes.
🐍 Exercise 2 (research): why quantise with μ-law?
Quantise speech-like signals of different loudness to 256 linear or μ-law levels and compare SNR.

WaveNet in AI, robotics and aerospace

  • Voice interfaces: neural vocoders give natural speech for cockpit, vehicle and robot voice interfaces.
  • Acoustic monitoring: WaveNet-style causal stacks model engine and bearing sounds for anomaly detection.
  • Quantisation choices: logarithmic quantisation of sensor signals with wide dynamic range preserves quiet but important details.

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.” Proc. ICML.
  3. T. L. Paine et al. (2016). “Fast WaveNet generation algorithm.” arXiv:1611.09482.
  4. ITU-T (1972). Recommendation G.711: “Pulse code modulation (PCM) of voice frequencies.”