Home / Chapter 9 · Images, video and audio
    Last edited · 17 min read

    Use with AI

    Voice, speech and music

    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 wordsA 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 frame stored in three layers of codes

    stored numbers
    distance from the frame vector
    frame vectorsum of the chosen vectorscodebook vectors, shorter in each successive codebook

    Illustrative: two-dimensional vectors and 8 entries per codebook instead of high-dimensional vectors and 1,024 entries. DAC also transforms the vectors before selecting an entry. The principle of encoding the error is the same.

    The same voice with 1, 2, 4 and 9 layers of codes: listen and compare the spectrogram

    The recording comes from LibriSpeech, a set of books read aloud for LibriVox (CC BY 4.0). It was resampled from 16 kHz to 44.1 kHz and encoded with the open DAC codec in its 44.1 kHz version (Descript, 2023, MIT licence), and the versions were decoded from the first 1, 2, 4 or all 9 layers of codes. The bitrate comparison uses the uncompressed 44.1 kHz recording as its baseline. The bitrate shown (the number of bits per second of recording) is that of the codes. The files on this page are saved at high quality, so that extra compression does not mask the differences between versions. Spectrogram: time runs horizontally, frequency vertically up to 8 kHz, because that is all the source recording covers; brighter bands mean more energy, and all versions use the same scale.

    How many codes per second of sound

    Three families of generators and their errors

    What the network computes in each pass, and when the result is ready

    Schematic: 6 frames and 4 layers of codes instead of hundreds of frames and 4–⁠8 layers, and for F5-TTS 4 spectrogram bands instead of 100. It shows the order described in the papers, not measured times.

    Cloning, voice conversion, dubbing and live conversation

    Music, sound effects and length

    MusicGen’s sliding window: a longer track from 30-second windows

    prompt: the last 12 s of the previous window18 new secondschorus from second 10

    Each successive window gets the last 12 s of the previous one as its prompt and appends 18 s. Even the second window, which starts at 18 s, excludes the chorus at 10 s, so the model has no direct access to it; a similar melody may return by chance or through traces in the last 12 s, but nothing guarantees it. This is the same mechanism as extending a video in “Video generation” and cutting off the oldest history of a conversation with an LLM (see “The context window and agents”). Defaults from the MusicGen code: a 30 s window, with each successive window starting 18 s after the previous one.

    Check yourself

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

    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.

    Po polsku

    Kodek neuronowy dzieli dźwięk na ramki. Każdą zapisuje kilkoma kodami, czyli numerami wpisów w słownikach: pierwszy kod daje zgrubne przybliżenie, a kolejne opisują coraz drobniejsze poprawki. Model może przewidywać te kody tak jak tokeny. DAC to ok. 86 ramek i 775 kodów na sekundę. Model kodekowy dopisuje kody po kolei jak LLM i może mówić na żywo, jeśli generator i dekoder działają krótkimi kawałkami, ale bywa, że gubi albo powtarza słowa. Model generujący cały spektrogram naraz, np. F5-TTS, musi z góry znać długość i oddaje wypowiedź dopiero na końcu. Gdy długość nagrania przekracza limit modelu, dzieli się je na fragmenty, a na łączeniach może się zmieniać intonacja albo gubić struktura utworu; niektóre modele muzyki generują kilka minut naraz.

    Follow-up questions (4)
    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

    Report an error · Suggest a fix