Skip to content

Generating sound and music: AudioLM to Bark

Most audio generators write codec tokens with language models, in a hierarchy (AudioLM, MusicLM, Bark, Jukebox) or with delayed codebooks (MusicGen, AudioGen); AudioLDM 2 runs latent diffusion. Rights and evaluation follow.

Advanced ~18 min12 steps

What runs in CodeSplash

You will be able to

  • Explain hierarchical token generation, from semantic to coarse to fine tokens
  • Lay out MusicGen's delay pattern for several codebooks
  • Describe latent diffusion for audio and the multi-level codes of Jukebox
  • Evaluate generated audio for quality, prompt adherence and copying, and check the rights to its weights and data

Read first

01

Audio as tokens, again

Read

The codec lesson turned audio into a few integer tokens per frame. Generation then becomes language modeling: predict the next token, sample, repeat, and let the codec's decoder play the result. A codec language modelCodec language modelA language model over neural-codec tokens. It writes audio as token sequences, and the codec's decoder turns them into sound. can continue a prompt, follow a text description, or both.

Two problems shape the designs. Audio needs long context: a few seconds of music span thousands of tokens. And each frame has several codebooks, so "next token" must be defined across them.

02

AudioLM: meaning first, sound second

Read

AudioLM generates in three stages. Semantic tokens, clusters of a self-supervised speech model's features (discrete speech unitsDiscrete speech unitsTokens made by clustering self-supervised speech features. They stand for sounds and let language-model tools generate speech.), carry content and long-range structure at a low rate. Coarse acoustic tokens, the first codebooks of a neural codec, add voice and recording conditions. Fine tokens add detail:

p(s,c)=p(s)  p(ccoarse∣s)  p(cfine∣s,ccoarse).p(s, c) = p(s)\; p(c^{\text{coarse}} \mid s)\; p(c^{\text{fine}} \mid s, c^{\text{coarse}}).

Given a few seconds of speech or piano, it continues them plausibly, without any text. The reference's example adds the three stage losses: 2.16.

Reference · AUD056 · Explained hereAudioLMA hierarchical generative audio framework combining semantic tokens with acoustic codec tokens. It models continuation from audio context and demonstrates language-model-style generation without requiring text…
03

MusicLM and Bark: the hierarchy with prompts

Read

MusicLM puts a text condition on top of AudioLM's hierarchy. A joint music–text embedding model maps the prompt, "calm piano over soft rain", into the space the semantic stage is conditioned on. Its three stage losses sum to 2.16 in the reference's example.

Bark runs a similar text-to-semantic-to-coarse-to-fine chain over codec tokens and can produce speech, laughter and music-like sounds. It samples, so it isn't a deterministic text reader: it may skip, add or change words. Its staged losses give 2.16 on the same toy table.

Reference · AUD060 · Explained hereMusicLMA research text-to-music framework combining a music–text embedding space with hierarchical semantic and acoustic token generation. Reference · AUD063 · Explained hereBarkA publicly documented text-prompted generative audio model with hierarchical semantic and acoustic token stages.
04

MusicGen: one model, delayed codebooks

Read

MusicGen uses a single Transformer over EnCodec tokens. To predict several codebooks at once without a hierarchy of models, it uses a delay patternCodebook delay patternA way to predict several codebooks with one language model: each codebook's tokens are shifted a step, so they're predicted together.: codebook qq is shifted qq steps, so at each step the model emits one token per codebook, and each depends on the earlier codebooks of its frame from previous steps.

Python
T, Q = 5, 3                                   # frames, codebooks
for q in range(Q):
    row = ["."] * (T + Q - 1)
    for t in range(T):
        row[t + q] = str(t)                   # frame t of codebook q is predicted at step t + q
    print(f"book {q}: " + " ".join(row))
R
T <- 5; Q <- 3                                # frames, codebooks
for (q in 0:(Q - 1)) {
  row <- rep(".", T + Q - 1)
  row[(0:(T - 1)) + q + 1] <- as.character(0:(T - 1))  # frame t of book q at step t + q
  cat(sprintf("book %d: %s\n", q, paste(row, collapse = " ")))
}

Text, and for some versions a melody, condition the model. Two codebook losses on the reference's toy table sum to 0.919.

Reference · AUD058 · Explained hereMusicGenA controllable music generator using one language model over multiple codec-token streams with an interleaving/delay pattern. It supports text conditioning and, for appropriate variants, melody conditioning.
05

AudioGen: sound effects from words

Read

AudioGen applies the same idea to environmental sound: a Transformer writes codec tokens conditioned on a text description, p(c∣d)=∏tp(ct∣c<t,d)p(c \mid d) = \prod_t p(c_t \mid c_{<t}, d). Prompts such as "footsteps on gravel, wind" need sounds to be layered at once, which makes prompt adherence harder than for single sources. Its conditional token loss on the reference's toy table is 0.459.

Decoding settings matter: a higher temperature gives more varied, less faithful sound. Keep the original paper and the later AudioCraft implementation apart when you cite results.

Reference · AUD057 · Explained hereAudioGenA text-conditioned environmental-audio generation framework modeling discrete acoustic tokens. It aims to produce sounds matching descriptions rather than only speech or music.
06

Sampling the next token

Explore

DExplorable · Temperature and top-p

What do the sampling settings on a language model actually change?

With these settings, how likely is the single most likely token?

0.50
How sure?
1.00

Below 1 sharpens the distribution; above 1 flattens it.

1.00

Keep the likeliest tokens until they hold this much probability.

12
200

“The p-value tells you how extreme”

surprising0.364unusual0.221likely0.148extreme0.099compatible0.066rare0.045strong0.024much0.016big0.010true0.005purple0.001sandwich0.000
  • With these settings
  • Default (temperature 1, no cut-off)

Twelve sampled tokens: extreme · surprising · surprising · unusual · rare · rare · unusual · surprising · rare · extreme · surprising · likely

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.

Every codec language model in this lesson chooses tokens this way. Lower the sampling temperatureSampling temperatureRescales a language model's next-token scores; low values sharpen the distribution, high values flatten it. and outputs grow repetitive and safe; raise it and they grow varied and erratic. For audio, too low often loops a phrase, too high adds noise and drift. Report the decoding settings with any sample.

DExplorable · Decoding: greedy, beam search and sampling

How does the way we pick tokens change the sentence a language model writes?

Method

Greedy takes the likeliest token each step; beam search keeps several partial sentences; sampling draws.

3

Beam search only: partial sentences kept at each step.

Length normalization

Total log-probability always favors shorter sentences; normalizing by length offsets that.

0.60

GNMT only: divide by ((5 + length) / 6)^α.

1.00

Sampling only: below 1 sharpens, above 1 flattens, as in llm-sampling.

10

Sampling only: keep the k likeliest tokens.

1.00

Sampling only: keep the likeliest tokens until they hold this much probability.

8

Tokens before the search stops.

“the data fits well today </s>”

Change the sample to draw another sentence from the same settings.

</s>0.012the0.500a0.400model0.012data0.012noise0.012fits0.012well0.012badly0.012today0.012
Log-probability of the result
−4.239
Tokens
6
Normalized score
−4.239
Gain over greedy (log-probability)
−0.419
  • Puzzle: Find a sentence more likely than greedy's.
  • Puzzle: With beam search, make a sentence of five or more tokens win.
Sampling writes “the data fits well today </s>”: log-probability −4.239 over 6 tokens. Greedy's sentence has log-probability −3.820. The toy model's probabilities are fixed; only the way of choosing changes.

Sampling writes “the data fits well today </s>”: log-probability −4.239 over 6 tokens. Greedy's sentence has log-probability −3.820. The toy model's probabilities are fixed; only the way of choosing changes.

07

AudioLDM 2: latent diffusion

Read

AudioLDM 2 doesn't write tokens. Text is first turned into a sequence of general audio features, a "language of audio"; a latent diffusionLatent diffusionRuns diffusion on an autoencoder's compact codes instead of raw data, then decodes; cheaper, but bounded by the autoencoder. model then generates a compressed audio latent conditioned on it; a decoder and a vocoder render the waveform. One pipeline covers sound effects, speech and music within its training coverage.

The core is the usual noise-prediction error, in latent space: 0.0055 in the reference's example.

Reference · AUD059 · Explained hereAudioLDM 2A general audio-generation framework using a learned audio representation as an intermediate conditioning language and latent diffusion for waveform-related generation.
08

Jukebox: raw audio, three levels

Read

Jukebox generates songs as raw audio, with singing. A multi-level VQ-VAE compresses audio into codes at three time scales; the coarsest level carries the song's structure. Autoregressive priors generate the top level from genre, artist and lyrics, then upsamplers fill in each finer level. The VQ-VAE's commitment term is 0.0033 in the reference's example.

It showed raw-audio music generation was possible, at extreme compute: minutes of sampling per second of audio on large GPUs.

Reference · AUD061 · Explained hereJukeboxA music-generation system learning compressed audio codes at multiple temporal scales and autoregressive priors over those codes.
09

Rights and evaluation

Read

Generators can reproduce training material: a melody, a voice, a recognizable recording. Check the terms of the training data, the code and the weights separately; several models here have non-commercial weights or none public. Evaluate on separate axes: overall quality (Fréchet audio distanceFréchet audio distanceThe Fréchet distance between Gaussian fits to embeddings of real and generated audio. The embedding model is part of the metric. against real audio, and listening tests), prompt adherence (a CLAP score, with its blind spots), diversity, and copying, by searching for near-duplicates of training clips.

DExplorable · Scoring generators: FID, precision and recall

Can one number say how good generated samples are?

How will this generator's precision and recall come out?

How sure?

Generator

The real data is a ring of 8 clusters. Each generator gets something different wrong.

Feature extractor

FID and the k-NN scores compare features, not raw samples. Real FID uses a vision network; here, four simple maps.

200

How many real and how many generated samples are compared.

3

Each sample's ball reaches its k-th nearest neighbor in its own set.

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.

10

Where it stands in CodeSplash

Read
EntryIn CodeSplash
AudioLM (AUD056)Explained here; no public weights
AudioGen (AUD057)Explained here; non-commercial weights
MusicGen (AUD058)Explained here; non-commercial weights
AudioLDM 2 (AUD059)Explained here; non-commercial weights
MusicLM (AUD060)Explained here; no public weights
Jukebox (AUD061)Explained here; its terms and compute rule it out
Bark (AUD063)Explained here

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

11

Check: generating audio

Checkpoint

Check yourself

What do AudioLM's semantic tokens carry that its acoustic tokens don't model as well?

Show the answer

Answer: b

Clusters of self-supervised features capture what is said or played; codec tokens capture how it sounds.

Check yourself

Does AudioLM need text to generate speech?

Show the answer

Answer: a

It models audio tokens directly. Text conditioning came in later systems built on the same hierarchy.

Check yourself

How does MusicLM bring a text prompt into an AudioLM-style hierarchy?

Show the answer

Answer: b

The embedding links descriptions and music; the hierarchy then generates tokens as before.

Check yourself

A colleague wants to reproduce MusicLM results locally. What's the obstacle?

Show the answer

Answer: b

A paper's capabilities don't come with a checkpoint. Name any reproduction you use.

Check yourself

Why shouldn't Bark be used where the exact words matter, such as reading instructions aloud?

Show the answer

Answer: b

Generative sampling trades faithfulness for expressiveness. Check the output against the text.

Check yourself

Which chain does Bark's documented design follow?

Show the answer

Answer: b

It mirrors AudioLM's hierarchy, with text at the top.

Check yourself

With a delay pattern, 4 codebooks and 4 frames, how many generation steps does MusicGen need?

Show the answer

Answer: 7

Codebook qq is shifted by qq steps, so the last token, frame 3 of codebook 3, comes at step 3+3=63 + 3 = 6, counting from 0: 4+4−1=74 + 4 - 1 = 7 steps.

Check yourself

What does the delay pattern let MusicGen avoid?

Show the answer

Answer: a

One Transformer emits one token per codebook per step, each conditioned on earlier codebooks of its frame from previous steps.

Check yourself

Why is prompt adherence hard for AudioGen-style sound-effect generation?

Show the answer

Answer: b

"Footsteps on gravel, wind, a distant dog" asks for three overlapping sources in the right balance.

Check yourself

You raise the sampling temperature for AudioGen. What do you expect?

Show the answer

Answer: b

Temperature flattens the token distribution: more diversity, less adherence. Report it with any sample.

Check yourself

What does AudioLDM 2's diffusion model generate?

Show the answer

Answer: b

A decoder and a vocoder turn the latent into sound afterwards.

Check yourself

Why can't CodeSplash offer AudioLDM 2 or MusicGen models?

Show the answer

Answer: b

Usable weights are a separate question from published code.

Check yourself

How does Jukebox handle the length of raw-audio songs?

Show the answer

Answer: b

The top level carries song structure at a low rate; lower levels add detail.

Check yourself

What limited Jukebox's practical use?

Show the answer

Answer: a

It proved raw-audio song generation possible; later codec-token models made it far cheaper.

12

Recap

Recap
  • Codec language models write audio as tokens; AudioLM, MusicLM and Bark go semantic → coarse → fine.
  • MusicGen predicts several codebooks with one model by delaying each; AudioGen does the same for sound effects.
  • AudioLDM 2 runs latent diffusion; Jukebox stacks three levels of VQ-VAE codes.
  • Check rights and evaluate quality, adherence, diversity and copying separately. All are explained here.

Concepts in this lesson