Skip to main content
ZombieMutex

30 results · ↑ ↓ navigate · Enter open · Esc close

All writing
November 9, 20263 min read

I built a tiny neural audio codec. Then I listened to the results.

A trained nonlinear encoder, vector-quantized codebook and decoder are interesting. An idealized low bitrate is not the same thing as good reconstructed speech.

By

Share

Send this article to someone or copy its link.

Suggest a correction

Reader tools

3 min remaining · 0% of article

Select a passage and choose Highlight selection to save it. Local browser storage only. Shift+F toggles focus.

I implemented a small vector-quantized audio autoencoder to examine what gets lost when continuous samples become discrete code indices. The model trains, the reconstruction improves, and the quality numbers make it impossible to pretend that a tiny bitrate means good audio.

So I built a small vector-quantized audio codec from scratch with NumPy. No pretrained encoder, no codec service and no magic downloadable model. Just a nonlinear encoder, a trained discrete codebook, a nonlinear decoder and enough bookkeeping to see where it struggles.

The actual computation

The input is mono 8-kHz PCM split into 64-sample frames. A learned encoder maps each frame into a 12-dimensional latent vector. I quantize that vector against 32 learned embeddings using squared Euclidean distance, keep the winning code index, and reconstruct the frame using a learned decoder.

In simplified notation:

text
z = tanh(x @ W_encoder + b_encoder)
k = argmin_j ||z - codebook[j]||^2
q = codebook[k]
x_reconstructed = tanh(q @ W_decoder + b_decoder)

The nearest-codeword choice is discrete, so gradient descent doesn't flow through it directly. The prototype uses a straight-through approximation for the encoder path, a commitment penalty to keep the encoder near selected codewords, and a centroid-style codebook update. This is a tiny research implementation, not the architecture of a modern high-quality neural speech codec.

The result I actually measured

I generated a repeatable dataset of harmonic, voiced synthetic signals with different fundamental frequencies. After 280 training steps, the local run reported:

MeasurementResult
Reconstruction MSE before training0.04164
Reconstruction MSE after training0.01217
Reconstructed-signal SNR5.24 dB
Active codewords32 of 32
Raw code-index bitrate625 bit/s at 8 kHz
μ-law sample baseline SNR37.89 dB
μ-law sample baseline bitrate64 kbit/s

That is a substantial reduction in reconstruction error from the untrained model. It is emphatically not good speech reconstruction. The bitrate calculation counts five bits per 64-sample frame, excluding codebook weights, model storage, transport and framing. You cannot compare 625 bit/s and 64 kbit/s without also comparing fidelity and implementation cost.

The 8-bit μ-law baseline has dramatically better SNR on the same synthetic input. It's not a learned neural codec, and it isn't being used as a telephone-transport conformance test. It's there to stop me from congratulating myself over a very compressed but fairly mangled signal.

What I'd measure next

A useful production-oriented codec study would add real licensed speech, multilingual and speaker-separated holdouts, train/validation/test isolation, objective quality measures, listening tests (MOS or ABX), packet-loss concealment, decoder speed, model size, memory use and streaming latency. I'd test whether residual VQ, temporal context and learned decoder architectures improve the quality-versus-bitrate curve rather than optimizing bitrate in isolation.

There's also an operational reason to care about discrete latent representations: they can become tokens for downstream generative speech models. But quantized latents are not automatically good generative targets. Codebook collapse, temporal alignment and speaker/prosody preservation are separate experiments.

I like research projects where the numbers force me to change my mind. This was one of them. The training code works and the reconstruction improves; the result also tells me exactly how far away this toy architecture is from good voice quality.

Related: Neural Audio Codec & Vector Quantization · Speech & Audio ML projects · Streaming speech inference.

Related technical notes with overlapping topics.

Discuss a passage

Select a paragraph above, copy it with its article link, then paste into the discussion. Don't include private data.

Jump to discussion ↓

Public conversation / GitHub Discussions

Discuss this article

Read and reply using GitHub Discussions. A GitHub account is needed to post. Comments are public and subject to GitHub moderation.

For privacy, the external giscus widget does not load until you choose to open it. Opening it connects your browser to giscus and GitHub. Do not post credentials or private project data.