> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lokutor.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Unity: lip sync

> Move a mouth with the voice in Unity: Lokutor Lip Sync with Oculus, Ready Player Me, VRChat, VRM, VRoid and ARKit blend shapes, your own names, jaw bones and 2D drawings, timed on the audio being heard

The server sends the mouth shape of every sound of the voice ([15 visemes](https://docs.lokutor.com/sdk/visemes.md), free, in every language) and **Lokutor Lip Sync** plays them on the clock of what is being **heard**, so the mouth stays in time through buffers, pauses and interruptions. Visemes are on by default.

## Set it up

Nothing to do for a face it recognises: the agent adds the component by itself and moves every mesh under it whose mouth it knows. To choose the meshes or change the feel, **Add Component > Lokutor > Lokutor Lip Sync** on the character (the agent's object, under it or above it) and fill in **Faces**. Teeth and tongue meshes go there too if they have the shapes.

The mouth is recognised by the names of its blend shapes. Upper and lower case do not matter, nor what an FBX exporter puts in front (`Face.viseme_aa`):

| Blend shapes | `Rig` | How they are used |
| :- | :- | :- |
| `viseme_aa`, `viseme_PP`... (Oculus, Meta, Ready Player Me), `vrc.v_aa` (VRChat), `v_aa`, `vis_aa` | `Visemes` | The 15 visemes, one to one. `viseme_I`, `viseme_O` and `viseme_U` are `ih`, `oh` and `ou`. At least 8 of them. |
| `aa` `ih` `ou` `ee` `oh` (VRM), `Fcl_MTH_A`... (VRoid), `MTH_A`..., `mouth_a`... | `Vrm` | The five vowels; the consonants are mixed from them. |
| `jawOpen`, `mouthFunnel`, `mouthPucker`... (ARKit, 52 shapes) | `ArKit` | Mixed from the 52. |
| One of `mouthOpen`, `mouth_open`, `jawOpen`, `jaw_open`, `mouth_a`, `mth_a`, `open`, `a` | `MouthOpen` | How open the mouth is. |
| Anything else | `None` | Write a **Mapping**. |

```csharp theme={null}
void Start()
{
    var lips = GetComponentInChildren<LokutorLipSync>();
    Debug.Log(lips.Rig);                                   // Visemes
}
```

The agent's own **Face**, **Mouth Blend Shape** and **Jaw** still work for a simple mouth.

## Your own names

**Mapping** says which of your shapes make each viseme, and how much of each. In the Inspector, or:

```csharp theme={null}
lips.mapping.Add(new LokutorVisemeShape("aa", "gape", 0.8f));
lips.mapping.Add(new LokutorVisemeShape("oh", "gape", 0.5f));
lips.mapping.Add(new LokutorVisemeShape("oh", "kiss", 0.6f));
lips.mapping.Add(new LokutorVisemeShape("PP", "lips_closed", 1f));
lips.Bind();          // after changing faces or mapping while the game runs
```

The viseme names are `LokutorApi.Visemes`: `sil PP FF TH DD kk CH SS nn RR aa E ih oh ou`. `sil` is the mouth at rest and needs no shape.

## A jaw, or drawings

* **Jaw**: a bone or head part rotated around its local X axis; **Jaw Max Angle** is its widest. Jaws and blend shapes can be used together.
* **Mouth Sprite**: a SpriteRenderer. **Mouth Sprites** are four drawings (closed, slightly open, open, round), or **Viseme Sprites** gives one for each viseme. For a UI Image or a material, ask `MouthSprite()` which one it is.

For anything else read `MouthOpen` (0 to 1), `Current` (the strongest viseme) or `Weights` (the 15 of them), or listen to `onVisemeChanged`:

```csharp theme={null}
void Update() => animator.SetFloat("MouthOpen", agent.MouthOpen);
```

## The feel

| Field | Default | |
| :- | :- | :- |
| `intensity` | 1 | How far the mouth opens. |
| `lead` | 0.05 | Seconds the mouth leads the sound: people open before they speak. |
| `blend` | 0.07 | Seconds over which one shape melts into the next. 0.05 is crisp and cartoonish, 0.12 soft. Neighbouring shapes overlap, so a short one between two others never reaches its full weight, as in real speech. |
| `loudness` | 0.35 | How much quiet syllables close the mouth. The lips still meet on p, b and m. |
| `steppedFps` | 0 | Steps per second: 12 animates on twos, for a hand-drawn look. |

## Several voices, one mouth

A character can have a Lokutor Agent for conversation and a Lokutor Voice for [written lines](https://docs.lokutor.com/sdks/unity/speech.md). Put the voice on its own GameObject, because each plays through its own AudioSource; they share the character's Lokutor Lip Sync, and the mouth follows whoever is speaking.

## Without visemes

When a voice has none, the mouth follows its loudness (`gain` sets how much). To drive a mouth from audio of your own, call `PushVisemes` with its visemes, if it has them, and `Advance` every frame with how much of it has been heard:

```csharp theme={null}
void Update() => lips.Advance(recording.time, 0.3f, recording.isPlaying, Time.deltaTime);
```

`LipSync` and `MouthRig` are the same thing without the engine, for other renderers.

## With moods and expressions

It writes in `LateUpdate`, after the Animator, and only the shapes it found, so expressions on other shapes of the same mesh are yours. Mouth expressions (a smile, a frown) and visemes add up: fade yours to about a third while the character speaks. [Game characters](https://docs.lokutor.com/guides/game-characters.md#layers) has the whole recipe, and [Asset pipeline](https://docs.lokutor.com/guides/game-asset-pipeline.md) the shapes to model.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.