How does an LLM learn to understand speech with an audio encoder and adapter?
- Authors
- Name
- Amit Shekhar
- Published on
An LLM learns to understand speech by using an audio encoder that turns sound into vectors (lists of numbers), and an adapter that converts those vectors into the same kind of vectors that the LLM already reads for words. The LLM then reads these "audio tokens" just like it reads text tokens.
In this blog, we will learn about how an LLM learns to understand speech with an audio encoder and adapter. We will also see why an LLM cannot hear sound on its own, how sound becomes a picture-like spectrogram, how the audio encoder turns that spectrogram into vectors, how the adapter makes those vectors fit the LLM, how the whole system is trained step by step, and where this approach works well and where it fails.
We will cover the following:
- Why an LLM cannot understand speech on its own
- The three parts: audio encoder, adapter, and LLM
- How sound becomes numbers
- What is an audio encoder?
- What is an adapter?
- How the audio tokens and text tokens go together into the LLM
- How the model is trained
- Where this approach works well and where it fails
I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.
I teach AI and Machine Learning at Outcome School.
Let's get started.
Why an LLM cannot understand speech on its own
An LLM (Large Language Model) reads text. But, it does not read the letters directly. First, the text is cut into small pieces called tokens. Then, each token is looked up in a table, called the embedding table, and turned into a long list of numbers called an embedding. The LLM only ever works with these embeddings.
So, the input of an LLM looks like below:
"What is the weather today?"
↓
[What] [is] [the] [weather] [today] [?]
↓
6 embeddings, one vector per token
↓
LLM
Now, the question is: what happens when we give the LLM a voice recording of someone asking the same question?
The LLM cannot use it directly. A recording is not text. It is a long list of air pressure values, recorded thousands of times every second. There are no tokens in it, and there is no embedding table for it.
One of the ways to solve this is to first convert the speech into text using a separate speech-to-text model, and then pass that text to the LLM. This works, but we lose a lot of information on the way. The text "I am fine" looks the same whether the person said it happily or angrily. The tone, the emotion, the pauses, and the background sounds are all thrown away.
So, here comes the audio encoder and adapter approach to the rescue. Instead of turning speech into text, we turn speech directly into embeddings that the LLM can read.
The three parts: audio encoder, adapter, and LLM
The full system has three parts, connected one after another, like below:
+-------------------+
| Speech (audio) |
+-------------------+
↓
+-------------------+
| Audio Encoder |
+-------------------+
↓
+-------------------+
| Adapter |
+-------------------+
↓
+-------------------+
| LLM |
+-------------------+
↓
+-------------------+
| Text answer |
+-------------------+
Here, each part has one job:
- Audio Encoder: It listens to the sound and understands what sounds are present, and turns them into vectors.
- Adapter: It converts the vectors from the audio encoder into vectors that look like the LLM's own token embeddings.
- LLM: It reads those vectors, along with any text we give it, and writes the answer.
Let's say we have a person who speaks only French and a person who speaks only English. The audio encoder is the French speaker who heard the sound and understood it. The LLM is the English speaker who can answer questions. The adapter is the translator standing between them. Without the translator, the two of them cannot work together.
We will learn about each of them in detail.
How sound becomes numbers
Before jumping into the audio encoder, we must know what the audio encoder actually receives as input.
A microphone records sound as a wave. The computer stores this wave by measuring its height many times every second. For speech, a common choice is 16,000 measurements per second. So, a 10-second recording becomes 160,000 numbers.
These raw numbers are hard to learn from directly. So, most audio encoders first convert them into a spectrogram.
A spectrogram is a picture of sound that shows which pitches (frequencies) are present at each moment in time.
To build it, the audio is cut into tiny overlapping slices, for example, 25 milliseconds long, with a new slice starting every 10 milliseconds. For each slice, we measure how strong each pitch is. Then, we place all the slices side by side.
pitch
↑
high | . . # # . . . .
| . # # # # . . .
| # # . . # # . .
low | # . . . . # # .
+-----------------→ time
Here, # means a pitch is strong at that moment, and . means it is weak. Different speech sounds create different shapes in this picture. The sound "s" has a lot of high pitches, and the sound "o" has most of its energy in the lower pitches.
Many speech models use a special version called a log-mel spectrogram, which spaces the pitches the way the human ear hears them. For example, the original Whisper models, which are popular speech-to-text models from OpenAI, use 80 pitch bands, with one slice every 10 milliseconds.
So, now the speech is a picture-like grid of numbers. This is the input to the audio encoder.
Planning your move into AI?
No matter which tech domain you work in today, with your effort, you can transition to these roles:
- AI Engineer
- Forward Deployed Engineer
- AI Agent Engineer
- Harness Engineer
- Voice AI Engineer
- AI Architect
- LLM Engineer
- LLM Inference Engineer
- Gen AI Engineer
- MLOps Engineer
- ML Engineer
- Deep Learning Engineer
Our AI and Machine Learning Program at Outcome School takes you there.
What is an audio encoder?
An audio encoder is a neural network that takes a spectrogram and turns it into a sequence of vectors, where each vector describes what is happening in the audio during a short piece of time.
Many audio encoders are built with the Transformer encoder architecture. The steps go like below:
Step 1: A few convolution layers, which are small filters that slide over the spectrogram, look at nearby slices and combine them. This also reduces the number of time steps.
Step 2: The Transformer layers let every time step look at every other time step using Self Attention. So, the vector for one moment can use the context of the sounds before and after it.
Step 3: The output is one vector per time step.
For example, the Whisper encoder produces 50 vectors for every second of audio, which is one vector for every 20 milliseconds. So, a 10-second recording becomes 500 vectors.
Now, the next big question is: how does the audio encoder learn to produce useful vectors?
The answer is: it is usually trained earlier, on its own, on a huge amount of speech. A common way is to train it as part of a speech-to-text model, where it must produce vectors that help write the correct transcript. To do that well, its vectors must capture the sounds of the words. Along with that, they often keep some information about the speaker's tone and the background noise.
So, we do not build the audio encoder from scratch. We take an audio encoder that has already learned to hear, and we reuse it.
Now, let's move to the adapter.
What is an adapter?
At this point, we have a good set of audio vectors. But, there are three problems.
Problem 1: The vectors are the wrong size. The audio encoder's vectors have one size, for example, 1,280 numbers each. The LLM's token embeddings have a different size, for example, 4,096 numbers each. The LLM cannot read a vector of the wrong size.
Problem 2: The vectors speak a different "language". Even if the sizes matched, the numbers mean different things. Just for the sake of understanding, let's say that inside the LLM, one pattern of numbers means "weather" and another pattern means "question". The audio encoder never learned those meanings. It learned its own meanings.
Problem 3: There are too many vectors. 10 seconds of audio gives 500 vectors. But, the same 10 seconds of speech is usually only about 25 words of text. Feeding 500 vectors to the LLM is slow and uses a lot of memory.
So, here comes the adapter into the picture.
An adapter is a small neural network that sits between the audio encoder and the LLM. It shortens the sequence of audio vectors and converts each one into a vector that lives in the same space as the LLM's token embeddings.
The adapter is also called a projector or a connector.
A common adapter does two things:
Step 1: The adapter shortens the sequence. It groups neighboring vectors together. For example, it takes every 4 neighboring vectors and joins them into one long vector. So, 500 vectors become 125 vectors. Some adapters use pooling, which means averaging neighbors, or a convolution that skips steps, for the same purpose.
Step 2: The adapter projects each vector. It passes each grouped vector through a small network, often just one or two linear layers, to produce a vector of the LLM's size.
Let's see this with numbers:
+-------------------------------+
| Audio encoder output |
| 500 vectors x 1,280 numbers |
+-------------------------------+
↓
Group every 4 neighbors
↓
+-------------------------------+
| 125 vectors x 5,120 numbers |
+-------------------------------+
↓
Linear layers
↓
+-------------------------------+
| Adapter output |
| 125 vectors x 4,096 numbers |
+-------------------------------+
Here, we can see that the adapter output has the exact size the LLM expects. Each of these 125 vectors is now an audio token. It is not a word from the vocabulary, but the LLM can read it just like a word embedding.
There are other adapter designs too. One design uses a small set of learned "query" vectors that pick out the important information from the audio using attention, and always produce a fixed number of output vectors. But, the job is the same: shorten and translate.
Vision-Language Models use the same idea for images, where a projector turns image patches into tokens that the LLM can read. We have a detailed blog on Vision-Language Model (VLM) that explains this in depth.
This is how the adapter makes the audio encoder and the LLM work together.
A quick note for you
No matter which tech domain you work in, get familiar with these topics:
- LLM
- RAG
- MCP
- Agent
- Fine-tuning
- Quantization
We put it all together in one video:
AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization
No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.
Now, let's get back to the topic.
How the audio tokens and text tokens go together into the LLM
Now, we have audio tokens. Let's see how we give them to the LLM.
The audio tokens are placed inside the normal sequence of text token embeddings. Special marker tokens tell the LLM where the audio starts and ends.
Let's say the user sends a voice note and types the question "What is the speaker asking?". The input to the LLM looks like below:
[text] What is the speaker asking?
[marker] <audio start>
[audio] 125 audio tokens from the adapter
[marker] <audio end>
Here, the LLM sees one long sequence of vectors. Some came from the embedding table for text, and some came from the adapter. From the LLM's point of view, they are all just vectors in the same space.
Now, the LLM does what it always does. It looks at all the vectors using attention, and it predicts the answer one token at a time. For example, it writes "The speaker is asking about today's weather."
So, the LLM is not hearing the sound directly. It is reading the audio tokens that the adapter prepared for it.
How the model is trained
Now, let's see how this system learns to understand speech.
At the start, the adapter is brand new. Its numbers are random. So, its output is meaningless to the LLM. We must train it.
The common training recipe usually happens in stages.
Stage 1: Teach the adapter to translate
In this stage:
- The audio encoder is frozen, which means its parameters do not change.
- The LLM is frozen.
- Only the adapter is trained.
We give the system a huge number of pairs of speech and its correct transcript. For each pair, the input is the audio, along with an instruction like "Transcribe the audio." The target output is the correct transcript.
The training works like below:
Step 1: The audio goes through the frozen audio encoder and then through the adapter, and becomes audio tokens.
Step 2: The frozen LLM reads the instruction and the audio tokens, and tries to predict the transcript, one token at a time.
Step 3: We compare the LLM's prediction with the correct transcript and measure how wrong it is. This is the loss.
Step 4: The error flows backward through the LLM and reaches the adapter. Only the adapter's parameters get updated, so that next time, the LLM predicts the transcript better.
Here, the LLM is not changing at all. The only way to lower the loss is for the adapter to produce audio tokens that the LLM already understands. So, the adapter is forced to learn the LLM's "language". If the speech says "weather", the adapter learns to produce vectors that the LLM treats like the meaning of "weather".
Why do we freeze the LLM in this stage? Because the adapter is random at the start, and its output is noise. If we let the LLM learn from noise, it can damage the language skills it already has. Freezing it protects those skills.
Similarly, the audio encoder is frozen because it already knows how to hear well.
Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.
Stage 2: Teach the model to follow instructions about audio
After Stage 1, the system can transcribe speech. But, we want much more than transcription. We want it to answer questions about the audio, summarize a meeting, tell the emotion of the speaker, describe a sound like a dog barking, and etc.
So, in this stage, we use many kinds of tasks, like below:
| Input audio | Instruction | Target answer |
|---|---|---|
| "What is the capital of France?" | Answer the question. | The capital of France is Paris. |
| An angry customer call | What is the speaker's emotion? | The speaker sounds angry. |
| A 5-minute team meeting | Summarize this meeting. | The team agreed to ... |
| A dog barking | What sound is this? | It is a dog barking. |
In this stage, the adapter often keeps training, and in some recipes it is frozen. The LLM is also often lightly trained, usually with a method like LoRA, which adds a small number of new parameters to the LLM and trains only those. This lets the LLM get better at reasoning over audio, with a lower risk of forgetting its text skills.
Some systems also unfreeze the audio encoder in an extra stage, so that it can pick up details that the LLM finds useful.
This is how the system learns, step by step, to understand speech.
We have a complete program on Multimodal AI, Fine-tuning, and Low-Rank Adaptation (LoRA) - check out our AI and Machine Learning Program at Outcome School to learn them end to end.
Where this approach works well and where it fails
Now, let's understand where this approach works well.
Advantages:
- Reuses strong models: We reuse an audio encoder that already hears well and an LLM that already reasons well. We train only a small adapter from scratch.
- Cheaper training: The adapter is small, so Stage 1 needs far less compute than training a speech model from scratch.
- Keeps more information: The tone, emotion, and background sounds can pass through the audio tokens, unlike in a plain transcript.
- One model for many tasks: The same system can transcribe, translate, summarize, and answer questions about audio, just by changing the instruction.
Now, let's see where it fails.
Disadvantages:
- Long audio is expensive: Even after shortening, one minute of audio becomes hundreds of audio tokens. A long recording can quickly fill the LLM's context window, which is the maximum number of tokens it can read at once.
- Limited by the audio encoder: If the audio encoder did not learn to capture something, for example, very fine details of tone, the adapter cannot recover it.
- Data needs: Stage 2 needs a lot of good examples of audio paired with instructions and answers, and such data is harder to collect than plain text.
- Hallucination: Like any system built on an LLM, it can produce a confident answer that is not supported by the audio, especially when the audio is noisy or unclear.
- Understanding is not speaking: This setup lets the LLM understand speech and answer in text. To talk back in a voice, we need an extra part that turns the output into speech.
We have a detailed blog on Spoken Language Model that covers models that can both hear and speak.
Now we must have understood how an LLM learns to understand speech with an audio encoder and adapter, how sound becomes audio tokens, how the adapter translates them for the LLM, and how the whole system is trained step by step.
Frequently Asked Questions
What is an audio token?
An audio token is one vector that comes out of the adapter. It is not a word from the vocabulary, but it has the exact size of the LLM's token embeddings, so the LLM can read it just like a word embedding. For example, 10 seconds of audio can become 125 audio tokens.
Is an adapter the same as a projector?
Yes. The adapter is also called a projector or a connector. It is a small neural network that sits between the audio encoder and the LLM. It shortens the sequence of audio vectors and converts each one into a vector that lives in the same space as the LLM's token embeddings.
Why is the LLM frozen when the adapter is first trained?
The LLM is frozen because the adapter is random at the start, and its output is noise. If the LLM learned from that noise, it could damage the language skills it already has. Freezing it protects those skills and forces the adapter to produce audio tokens that the LLM already understands.
Can an LLM with an audio encoder and adapter reply in speech?
No. This setup lets the LLM understand speech and answer in text. To talk back in a voice, we need an extra part that turns the text output into speech. The audio encoder and adapter only handle the listening side.
That's it for now.
Thanks
Amit Shekhar
Founder @ Outcome School
You can connect with me on:
Follow Outcome School on:
