How to Build AI Lipsync, Part 3: Learning to Map wav2vec Features to Mouth-Shape Parameters
Hello!
In the previous installments of this series, we covered
- how audio features are extracted with wav2vec (Part 1) and
- how to correct cumulative drift in lipsync production (Part 2)
. This time, we finally step into the heart of the matter: integrating these techniques to actually generate mouth movements from speech.
This article covers the training process that converts the 768-dimensional acoustic features extracted by wav2vec into time-series data for 26 mouth-shape control parameters. This is not mere dimensionality reduction. It is a conversion from a high-dimensional vector representing the physical properties of sound into an entirely different modality: human mouth movement. To achieve this conversion, a neural network must learn the complex correspondence between phonemes and visible mouth shapes.
What makes this especially challenging is that the correspondence is dynamic, not static. The same phoneme takes different mouth shapes depending on the surrounding context, and there is also a temporal offset: the mouth begins moving before the sound is even heard. How do we model and train for such complex phenomena? In this article, we compare two powerful approaches — LSTMs and Transformers — and search for the best method from a practical standpoint.
1. The Essence of the Problem: Why Mouth-Shape Prediction Is Hard
1.1 The Same Phoneme, Different Mouth Shapes Depending on Context
To understand why lipsync is difficult, let's start with the Japanese phoneme ん ("n") as an example. Any Japanese speaker can pronounce this sound, yet the mouth shape actually varies substantially with the situation.
When you say さんぽ (sanpo, "a walk"), the lips already begin to close during the ん. That is because the following ぽ (po) is a bilabial plosive, which requires the lips to close completely. In contrast, for the ん in さんか (sanka, "participation"), the lips do not close. The following か (ka) is a velar plosive, articulated at the back of the mouth, so there is no need to close the lips.
This phenomenon is called coarticulation and is observed universally in natural human speech. Our brains unconsciously predict the upcoming sound and plan efficient mouth movements accordingly.
This predictive movement is precisely the key to achieving natural lipsync.
1.2 Mouth Movements That Precede the Audio
Even more interesting is the phenomenon of mouth movement preceding the actual sound. When human speech is filmed with a high-speed camera, the mouth can be seen starting to move 50 to 100 milliseconds before the sound is heard.
Plosives are the most striking example. When you produce the sound ぱ (pa), you first close your lips to build up pressure in the oral cavity, then release them to create the plosive. In other words, by the moment the sound is heard, the lips have already begun to open. If this temporal offset is not modeled accurately, the audio and the mouth movement appear out of sync, resulting in unnatural lipsync.
1.3 The Complex Phenomenon of Coarticulation
Coarticulation is not limited to the influence between adjacent phonemes; it extends over a much wider range. Consider, for example, the utterance ありがとうございます (arigatou gozaimasu, "thank you").
From this installment on, the mechanisms we discuss get a bit more involved, so we are bringing in "Professor Quo" and his student "Manabu" — their conversations will help us deepen our understanding!
To handle such complex phenomena, we need sophisticated machine learning models. In the next chapter, we take a detailed look at the first approach to this challenge: time-series modeling with LSTMs.
2. Time-Series Modeling with LSTMs
2.1 Why a Simple Neural Network Won't Do
The first approach that comes to mind might be a simple fully connected neural network that takes the wav2vec features at each time step as input and outputs the corresponding mouth-shape parameters. This approach, however, has a fatal flaw.
A simple neural network processes each time step independently and therefore cannot take temporal context into account at all. In the さんぽ (sanpo) example above, at the ん it cannot use the information that "ぽ comes next." As a result, it outputs the same mouth shape for every ん, producing extremely unnatural lipsync.
2.2 The Basic Idea of RNNs and Their Limitations
RNNs (Recurrent Neural Networks) emerged to solve this problem. An RNN is a neural network with "memory": it can process time-series data while retaining information about the past.
The basic idea of an RNN is to compute the current output using not only the current input but also the internal state from the previous time step. This makes predictions that take past context into account possible.
However, RNNs suffer from a serious issue known as the "vanishing gradient problem." As the sequence grows longer, the influence of past information decays exponentially.
2.3 The "Memory" Problem LSTMs Solve
LSTM (Long Short-Term Memory) is a special kind of RNN designed to solve this vanishing gradient problem. The LSTM's key innovation is the introduction of "gate mechanisms" that control the flow of information.
With these gate mechanisms, an LSTM can retain necessary information over long spans and appropriately forget what it no longer needs. In lipsync terms, it can hold on to information like "this utterance is a question" all the way to the end of the sentence, while forgetting the details of individual phonemes at the right time.
2.4 Why We Need Bidirectional LSTMs: Looking at Both Past and Future
A standard LSTM handles only the flow of information from the past to the present. In lipsync, however, future information matters too. The lips begin to close at the ん in さんぽ (sanpo) precisely because we know the ぽ is coming.
Bidirectional LSTMs solve this problem. They process the sequence in both the forward direction (past to future) and the backward direction (future to past), and integrate information from both directions at each time step.
With a bidirectional LSTM, mouth-shape prediction at each time step can take both past and future context into account. This is a crucial ingredient for achieving natural lipsync.
3. Designing an LSTM-Based Network
3.1 Overall Architecture (wav2vec to Mouth-Shape Parameters)
To get a visual understanding of the actual network structure, let's look at the architecture diagram above. It shows the entire conversion process from the audio waveform to the mouth-shape parameters, organized into three broad stages: input processing, the main network, and output generation.

3.2 The Role of Each Layer
Feature projection layer: reducing 768 dimensions to 384
The 768-dimensional features output by wav2vec contain every kind of information about the audio: speaker characteristics, emotion, environmental sounds, and the phonetic information we actually need, all mixed together. For lipsync, however, what matters is primarily the phonetic information and the related prosodic information.
The role of this layer is to extract only the information needed for mouth-shape prediction from the high-dimensional 768-dimensional space and compress it into a more manageable 384 dimensions. Beyond a simple linear transformation, it combines LayerNormalization for normalization, a ReLU activation for nonlinearity, and Dropout to prevent overfitting, achieving robust feature extraction.
Bidirectional LSTM layers: learning temporal patterns
These layers are the heart of the network. The forward LSTM and the backward LSTM each maintain a 512-dimensional hidden state, together producing 1024 dimensions of contextual information.
The forward LSTM processes こ→ん→に→ち→は (ko → n → ni → chi → wa) in order, accumulating at each step the information of "what has been said so far." The backward LSTM processes the sequence in reverse, providing the information of "what will be said next." Integrating the two yields a representation at each time step that accounts for both past and future context.
Stacking three LSTM layers allows the network to learn more complex temporal patterns. You can think of the first layer as capturing basic phoneme transitions, the second layer coarticulation patterns, and the third layer longer-range dependencies.
Output projection layer: converting 384 dimensions to 26
The final output layer converts the 1024-dimensional contextual representation produced by the LSTM into the 26 mouth-shape parameters. Here too, the transformation proceeds in stages (1024 → 256 → 128 → 26) to avoid abrupt information compression.
Especially important is choosing activation functions to match the characteristics of each parameter. Parameters that range from 0 to 1, such as jaw_open and mouth_open, use a Sigmoid function, while parameters that range from -1 to 1, such as lip_corner_left, use a Tanh function.
3.3 Why This Architecture Works
The reason this network architecture is effective is that it mimics the human speech mechanism.
First, the feature projection layer corresponds to the human auditory system: the process of extracting only speech-related information from the sound entering the ears. Next, the bidirectional LSTM layers correspond to the brain's language-processing regions, integrating past context and future plans to generate appropriate motor commands. Finally, the output projection layer corresponds to the motor control system, converting abstract commands into concrete muscle movements.
An LSTM network designed this way can learn efficiently even from limited data and generate natural lipsync.
Summary
In this article, we began exploring the core of lipsync technology: converting wav2vec features into mouth-shape parameters.
We got to the heart of why this problem is hard. Through the coarticulation example of the same sound ん taking different mouth shapes in さんぽ (sanpo) and さんか (sanka), we saw how much context matters. The phenomenon of the mouth starting to move 50 to 100 milliseconds ahead of the audio also speaks to the complexity of lipsync.
As a first approach to this time-series problem, we walked through LSTMs in detail. Through the dialogue between Professor Quo and Manabu, we learned how the LSTM's gate mechanisms (forget, input, and output gates) solve the RNN vanishing gradient problem. The ability of bidirectional LSTMs to consider both past and future context is especially important.
Finally, we introduced an example of an LSTM-based network: a projection layer that compresses the 768-dimensional wav2vec features to 384 dimensions, bidirectional LSTM layers that learn temporal patterns, and an output layer that generates the 26 mouth-shape parameters.
Next time, we will move on to the more practical topics of data preparation and the training process, and also look at the limitations of LSTMs and a newer approach: the Transformer.
See you in the next installment!