## Voice, speech and music

*Images, video and audio*

*Last edited: 13 November 2026*

A speech or music model often works like an LLM: a codec turns sound into numbers, and the model appends them one after another. Other models denoise the whole recording at once, like an image model, and the way a model generates determines its typical errors and how long a recording it can generate coherently.

**In plain words:** A codec stores sound the way an artist makes a sketch: the first line gives the shape, each subsequent line adds shading and texture, and the first few lines alone already show what the drawing is of. A speech generator draws sketch after sketch like this, many times a second. A voice clone means showing it a few of someone else’s sketches so that it draws in that style.

### Why a neural codec, and how it stores sound

- One second of CD-quality sound is 44,100 samples per channel, too many for a model to predict quickly one by one. Like MP3 or Opus, which is used in browser calls, a neural codec uses lossy compression, but it stores the result differently: each short stretch of the recording, called a frame, becomes a fixed number of codes, which are indices into learned tables of vectors called codebooks. That comes to several hundred codes per second or more, and only about a hundred in codecs built for speech alone. A model can predict such numbers the way it predicts tokens: each one is a choice of one entry out of about a thousand in a codebook. (Opus is an audio codec, an IETF standard from 2012; it shares only its name with the Claude Opus model.)
- The codec’s encoder cuts the recording into short frames and turns each into a vector of numbers. It then stores that vector as several approximations, like writing a number digit by digit: the first codebook gives a rough approximation, and each successive one encodes what the previous ones missed (residual vector quantisation, RVQ). A codebook works like the embedding table from “Vectors and matrices”, only in the other direction: the encoder looks for the nearest vector and stores its number, and the decoder adds up the vectors the numbers point to. For the generator, a code is a token. A layer of codes contains one code per frame, all from the same codebook. So every frame has one code from each layer, and the layers are not successive moments of the recording.

*Interactive widget on the page: One frame stored in three layers of codes.*

*Interactive widget on the page: The same voice with 1, 2, 4 and 9 layers of codes: listen and compare the spectrogram.*

### How many codes per second of sound

- An example with DAC, the codec in the widget: one second of a recording at 44.1 kHz is 44,100 samples. The encoder makes one frame out of every 512 samples, about 86.1 frames per second, and stores each frame as 9 codes, numbers from 0 to 1,023, so 10 bits each. That is about 775 codes and 7.75 kbit/s instead of 705.6 kbit/s for uncompressed mono (44,100 samples of 16 bits). Frame rates and code counts differ by codec: EnCodec at 24 kHz has 75 frames per second with 2–32 codes each, and Mimi from Moshi (2024) only 12.5 frames per second with 8 codes each, so that long conversations take fewer tokens.
- Each successive layer of codes describes finer detail of the sound, which follows from RVQ. The first layers alone already give usable sound, because in training the codec often has to reconstruct the sound from only the first few layers (quantiser dropout). That is why one layer in the widget already gives intelligible speech, and each further layer brings the sound closer to the original. Generators rely on this order: they predict the codes of the first layers first, then those of the later ones.
- Compression loses some information: the decoder can add plausible-sounding detail, but it cannot faithfully reproduce detail the codes did not keep. EnCodec at 24 kHz covers frequencies up to 12 kHz at most, and typical codec artefacts are a metallic “s” and smeared drum hits. According to its authors, DAC (2023) achieves higher quality than EnCodec at a third of the bitrate, as assessed by automated measurements and expert listening tests.
- DAC and EnCodec codes are acoustic: they describe how the audio sounds and represent the words only indirectly, so a model struggles to preserve the spoken content over longer passages. That is why AudioLM (2022) added semantic tokens, 25 per second, taken from w2v-BERT, a model trained on speech alone, without transcripts. They carry content and rhythm but little information about the voice: in AudioLM, continuations generated from semantic tokens alone almost never preserved the original speaker’s voice. In Mimi, the first layer of codes is trained to carry content, and the other seven fill in how it sounds.

### Three families of generators and their errors

- Most of today’s speech generators belong to one of three families. A codec language model (neural codec language model) appends codes one after another, like an LLM. A flow matching model denoises the whole spectrogram at once, like an image model; a spectrogram is a picture of sound, described below, and flow matching is a variant of the diffusion covered in “Image generation”. A hybrid combines both: a language model sets the content, and a second network generates the acoustic detail.
- The widget shows four models from the first two families and what each computes in one pass of the network: the codec models VALL-E (speech), MusicGen (music, described below) and Moshi (live conversation), and F5-TTS, which generates the whole spectrogram at once.

*Interactive widget on the page: What the network computes in each pass, and when the result is ready.*

- Codec language models. VALL-E (2023) gets the text as phonemes, the units of pronunciation, and a 3-second voice recording as the start of the sequence, and then appends EnCodec codes the way an LLM appends tokens. It generates the first of eight layers of codes for the whole utterance, code by code. A second model then fills in the remaining seven layers, so the speech is ready only at the end. Newer models, such as Qwen3-TTS (2026), generate all layers frame by frame and use a codec that stores 12.5 frames per second. According to the authors, they return the first sound after about 0.1 s.
- Codec models make errors similar to an LLM’s (see “The next token”): nothing ties the text rigidly to the sound, so words are sometimes skipped or repeated, and the model can get stuck generating the same frame over and over.
- Flow matching on a spectrogram (Voicebox 2023, F5-TTS 2024). A mel spectrogram (on a scale matched to human hearing) shows the energy of the sound in 80–100 frequency bands from low to high, separately for every hundredth of a second. A transformer denoises the spectrogram of the whole utterance at once in 16–32 steps, like an image in diffusion, and a separate network, the vocoder, turns the spectrogram into a sound wave, just as an autoencoder’s decoder turns the grid into an image. The length has to be known before the start: F5-TTS computes it from the number of characters in the text, which fails on numbers and abbreviations. Words are omitted less often because the network sees the whole text and the whole utterance at once, but playback must wait until the whole utterance is ready.
- Hybrids, common among open models from 2025–2026: a language model sets the content and rhythm, and a second network produces the sound. CosyVoice 2 (2024) generates 25 semantic tokens per second with the Qwen2.5-0.5B model, and a flow matching model turns them into a spectrogram in short chunks, so playback can start before the rest exists. The second network gets the semantic tokens as an extra input, just as an image model gets the prompt vectors. VibeVoice (2025) pushes compression further: its codec stores only 7.5 frames per second. It describes each frame directly with a vector of numbers instead of choosing codes from codebooks, so according to the authors up to 90 minutes of recording fit in the language model’s context.
- Live conversation needs a model whose generator and decoder work in short chunks, from one frame to a fraction of a second: a streaming codec model such as Moshi, or a hybrid such as CosyVoice 2. If you prepare a recording ahead of time, choose the model by sound quality. Turn numbers, dates and abbreviations into words before synthesis, because each family gets them wrong in a different way.
- A long text is split into segments, and at the joins intonation and pace can change abruptly. Split the text at paragraph boundaries, use the same model and voice, and pass the neighbouring text if the API allows it: ElevenLabs has request stitching for this, which passes in earlier requests (as of November 2026). Regenerate only the segments that stand out.

### Cloning, voice conversion, dubbing and live conversation

- Cloning from a sample does not change the model’s weights: the sample is part of the input, like an example in a prompt. In VALL-E the sequence starts with the phonemes of the sample’s transcript (the transcript is supplied together with the recording), the phonemes of the new text, and the codes of the sample. The model appends the codes of the new utterance and keeps the voice of the sample, just as an LLM keeps the style of the start of a text. It can do this because it was trained on recordings of thousands of speakers (60,000 hours). *Cloning in VALL-E: the voice sample is the start of the sequence, and the model appends the codes of the new utterance to it. The model’s weights do not change.*
- In F5-TTS the sample’s transcript and the new text form one string of characters. The spectrogram of the sample is the known beginning, and the model generates the rest of the spectrogram.
- For cloning from a sample (Instant Voice Cloning), ElevenLabs recommends 1–2 minutes of recording rather than VALL-E’s 3 s. The clone copies the style of the sample: a calm recording gives a voice that renders shouting or laughter poorly. A professional voice clone is made, according to ElevenLabs, by fine-tuning the model (see “Fine-tuning and LoRA”) on at least 30 minutes of recordings. It is more stable on long texts, but it also picks up the noise and the microphone’s sound from the recordings.
- Cloning someone else’s voice requires the consent of the person it belongs to, and the provider’s safeguards do not replace that consent. According to ElevenLabs, its Voice Captcha verification confirms only that the person submitting the voice took part in the recording, not that the voice is theirs. A watermark, an inaudible signal added to the recording, can be detected only by a detector designed for that watermarking scheme, and not every generator adds one, so a missing watermark does not prove a recording is real. Store the consent record with the created voice, and let the person withdraw their consent.
- Voice conversion keeps the content, pace and intonation of a recording and replaces its tone quality (timbre): one technique described in the literature keeps the semantic tokens and generates the acoustic codes anew with a sample of the new voice. It is sometimes called “speech-to-speech”, but today that name usually means a live conversation model, described below.
- Classic AI dubbing is a pipeline: transcription split by speaker, translation, synthesis in each speaker’s cloned voice, and a mix that keeps the background. Translation changes the number of syllables, so you have to choose between naturalness, duration and fidelity, and a perfect voice will not fix a bad transcript.
- Live conversation can also be built as a pipeline: speech recognition, an LLM, synthesis. Only the transcript reaches the LLM, so the pipeline loses laughter and tone, and every stage adds latency: speech recognition usually waits for the end of the utterance, the LLM computes its first token, and synthesis generates the first sound. In OpenAI’s 2024 measurements, the pipeline used at the time answered after 2.8 s on average with GPT-3.5 and 5.4 s with GPT-4, while GPT-4o, which takes in and returns audio itself, answered after 320 ms on average. Today (as of November 2026) a pipeline with streaming at every stage gets down to about 1 s according to providers and is still common in production, because it leaves a transcript and lets you swap models; measure the latency in your own setup.
- Moshi (Kyutai, 2024) is one model instead of a pipeline. It listens and speaks at the same time: every 80 ms it takes in the codes of the sound from the other speaker’s microphone and generates a text token (an “inner monologue” ahead of the sound) and the codes of its own voice. In practice about 200 ms pass between sound at the input and the reply.
- In OpenAI Realtime, audio takes up the same context window as text: one audio token per 100 ms of your speech and one per 50 ms of the model’s speech, which is 600 and 1,200 tokens per minute. The window depends on the model: gpt-realtime-2 has 128,000 tokens, and the older gpt-realtime 32,000 (as of November 2026). A minute in which each side speaks for 30 s is 300 + 600 = 900 tokens, so 32,000 tokens is about 35 minutes of speech without pauses if all the audio stays in the window. This is an illustrative calculation, not a service limit: instructions and tool definitions take up space, and removing old turns frees it. Once the window is full, the API by default drops the oldest messages. As in text chat, the model processes the whole conversation so far for every reply, so the cost of a turn grows with the length of the session. Prefix caching (see “Prompt caching”) and trimming old turns help.

### Music, sound effects and length

- MusicGen (Meta, 2023) is a codec language model: 50 frames per second with 4 codes each, with the layers shifted by one frame as in the widget above. This lets one pass predict one code from each layer, while the code of the next layer for a given frame still comes after the code of the previous layer. MusicGen was trained on 30-second excerpts, so a longer track is generated with the sliding window shown below. As a result, key, tempo and arrangement can gradually move away from those at the start of the track.

*Interactive widget on the page: MusicGen’s sliding window: a longer track from 30-second windows.*

- Stable Audio generates continuous vectors with diffusion instead of codes from a codebook, with the duration given as a condition. The 2024 research model produced up to 4 min 45 s at once, because it compresses sound heavily and was trained on whole tracks, and Stable Audio 3 (May 2026) produces up to 6 min 20 s in its larger versions. So a long track can be generated without stitching, but a long context does not guarantee a good track structure.
- State the structure of the track explicitly instead of counting on the model to remember it: use tags in the lyrics, such as `[Verse]` and `[Chorus]` (this is how the Lyria documentation describes them), or a section plan in ElevenLabs Music, where a single section can be regenerated.
- Product limits (as of November 2026): ElevenLabs Music from 3 s to 5 min according to the service description (the API documentation allows up to 10 min), ElevenLabs sound effects up to 30 s with a loop option that repeats the same sound, Suno v6 up to 8 min in one generation.
- Closed products such as ElevenLabs, Suno and Udio do not publish their architecture, and Suno’s open Bark (2023) says nothing about how Suno v6 works. Results are non-deterministic, so save a good result as a file, and before using music in a product read the current licence and download terms.

### Check yourself

**Question:** How does a model turn text into speech or music, and why are a long recording and a live conversation separate problems?

**Short answer:** A neural codec splits sound into frames. It stores each frame as a few codes, the IDs of entries in codebooks: the first code gives a rough approximation, and the next ones describe finer and finer corrections. A model can predict these codes the way it predicts tokens. DAC produces about 86 frames and 775 codes per second. A codec model appends codes one after another like an LLM and can speak live if its generator and decoder work in short chunks, but it sometimes skips or repeats words. A model that generates the whole spectrogram at once, such as F5-TTS, has to know the length in advance and returns the utterance only at the end. When a recording is longer than the model’s limit, it is split into segments, and at the joins intonation can change or the structure of a track can get lost; some music models generate several minutes at once.

### Follow-up questions

- **A voice assistant has to answer in under half a second. Which synthesis model do you choose?** A model whose generator and decoder work in short chunks: a streaming codec model or a hybrid. If half a second is the limit on waiting for the first sound of the assistant’s reply, not just the synthesis time, the safest choice is a live conversation model that takes in and generates audio itself. A pipeline with separate speech recognition and an LLM usually reaches about 1 s according to providers; measure the latency of both options. A model that generates the whole spectrogram at once, such as F5-TTS, cannot start playback until the whole utterance is ready. Measure separately the time to first sound and whether synthesis keeps up with playback.
- **An audiobook synthesised chapter by chapter sounds as if the narrator changed at the joins. What do you fix?** Split the text at paragraph boundaries, use the same model, voice and settings for the whole book, and pass the neighbouring text or the previous requests if the API supports it (request stitching in ElevenLabs). For a text this long a professional clone is better than a clone from a sample, because it does not depend on a short sample in the context. Listen to the joins and regenerate only the segments that stand out.
- **A client wants the app to clone a voice from a recording the user uploads. What do you need to add beyond the API itself?** A record of the voice owner’s consent linked to the created voice, and a way to withdraw it that also deletes the voice. Verification at the provider, such as Voice Captcha, confirms that the person took part in the recording, not that they have the right to the voice. A watermark can be detected only by a detector designed for that watermarking scheme, so a watermark does not replace your own rules and their enforcement.
- **A MusicGen track extended to three minutes loses the opening melody after just the first minute. Why, and what do you do?** MusicGen uses a 30-second window and keeps only its last 12 seconds as the prompt when extending a track. Once the opening chorus falls outside those 12 seconds, the model no longer has it as a reference. You cannot fix this within MusicGen itself. Use a tool that takes the structure as tags or a section plan, and correct single sections. You can also choose a model that generates several minutes at once. Neither option guarantees a good structure, so listen to the whole track.

### Sources

- [Kumar et al.: High-Fidelity Audio Compression with Improved RVQGAN, DAC (2023)](https://arxiv.org/abs/2306.06546)
- [Wang et al.: Neural Codec Language Models are Zero-Shot Text to Speech Synthesizers, VALL-E (2023)](https://arxiv.org/abs/2301.02111)
- [Défossez et al.: Moshi, a speech-text foundation model for real-time dialogue (2024)](https://arxiv.org/abs/2410.00037)
- [Copet et al.: Simple and Controllable Music Generation, MusicGen (2023)](https://arxiv.org/abs/2306.05284)
- [ElevenLabs: Voice cloning, documentation (as of November 2026)](https://elevenlabs.io/docs/eleven-api/concepts/voice-cloning)
- [OpenAI: Realtime API, costs and context (as of November 2026)](https://developers.openai.com/api/docs/guides/voice-latency-cost)

Interactive page: https://howaiworks.dev/audio-generation/
