Speech & Audio AI Lab

Interactive labs for speech recognition, speech synthesis, and audio in general: in-browser DSP experiments, algorithms, datasets, and a learning path, without storing any recording.

43experiments

WaveNet

WaveNet

AdvancedSpeech Synthesis

Educational content in the form of a scientific draft that needs expert review before being adopted as an academic reference. No experimental result that was not actually run is shown here.

Definition

An autoregressive model that generates the waveform sample by sample using dilated causal convolutions, modeling the conditional distribution of each sample over fine quantization levels.

Mathematical Idea

The waveform probability is factorized by the chain rule: each sample is conditioned on those before it. Causal convolution prevents seeing the future, and doubling dilation expands the receptive field exponentially with depth. To turn the sample into classes, the range is compressed with μ-law and then quantized, and local conditions such as the mel spectrogram are added.

How It Works

  1. Compress the waveform with μ-law and quantize it
  2. Causal convolutions with dilation factors 1,2,4,…
  3. Gated units with residual and skip connections
  4. Sum the skip connections and softmax layers
  5. Pick the next sample and feed it back
  6. Repeat until the end of the waveform

Stages Diagram

  1. Waveform / local condition
  2. μ-law
  3. Dilated causal convolutions
  4. softmax
  5. Sample

Equations

$$p(x)=\prod_{t=1}^{T}p(x_t\mid x_1,\dots,x_{t-1})$$

Autoregressive chain factorization.

$$f(x)=\mathrm{sign}(x)\frac{\ln(1+\mu|x|)}{\ln(1+\mu)},\quad \mu=255$$

μ-law compression.

$$R=1+(K-1)\sum_{l}d_l$$

Receptive field of convolutions with length $K$ and dilation factors $d_l$.

Advantages

  • High natural quality in synthesis
  • Wide receptive field at moderate depth
  • Precise autoregressive modeling of the distribution

Limitations

  • Sample-by-sample generation is extremely slow in its original form
  • High computational cost
  • Needs data and a domain suited to a speaker

Use Cases

  • Vocoder in Tacotron 2
  • Speech synthesis and voice conversion in research
  • Speech enhancement in noise reduction research

Applied Example

10 layers with dilations 1 to 512 and kernel K=2 give a receptive field of 1+1023 = 1024 samples, i.e. 64 ms at 16 kHz.

Code Example

PythonImplemented and Tested
import numpy as np
def causal_dilated_conv(x, w, d):
    K = len(w)
    pad = np.concatenate([np.zeros((K-1)*d), x])        # left-only padding = causal
    return np.array([sum(w[k]*pad[t + (K-1-k)*d] for k in range(K)) for t in range(len(x))])
x = np.zeros(32); x[10] = 1.0                           # impulse at t=10
w = np.array([0.5, 0.5])
y = causal_dilated_conv(x, w, d=4)
print(np.nonzero(y)[0])                                  # [10 14]: no effect before t=10
dils = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
print(1 + (2-1)*sum(dils))                               # receptive field = 1024
mu = 255
f = lambda v: np.sign(v)*np.log1p(mu*np.abs(v))/np.log1p(mu)   # μ-law compression
print(np.round(f(np.array([-0.5, 0.0, 0.5])), 3))

References

  1. van den Oord et al.. WaveNet: A Generative Model for Raw Audio. arXiv (2016). DOI
  2. Shen et al.. Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions. arXiv (2017). DOI
  3. Prenger et al.. WaveGlow: A Flow-based Generative Network for Speech Synthesis. arXiv (2018). DOI

Audio processing in the experiments takes place inside your browser. Audio, texts, and conversations are not saved on the server. Privacy Policy