> ## 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.

# Godot: lip sync

> Move a mouth with the voice in Godot: LokutorLipSync with Oculus, Ready Player Me, VRChat, VRM, VRoid and ARKit blend shapes, your own names, jaw bones and 2D sprites, 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 `LokutorLipSync` 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

Add a `LokutorLipSync` node beside the LokutorAgent (or above it, under the same character) and drag the face meshes into **Faces**. The agent finds it by itself. 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` | `MOUTH_OPEN` | How open the mouth is. |
| Anything else | `NONE` | Write a **Mapping**. |

```gdscript theme={null}
func _ready() -> void:
    var lips := LokutorLipSync.new()
    lips.faces = [$King/Skeleton3D/Face]
    add_child(lips)
    $King/Head/LokutorAgent.lip_sync = lips
    print(LokutorLipSync.Rig.keys()[lips.rig()])     # VISEMES
```

The agent's own **Face**, **Mouth Blend Shape** and **Jaw** are shortcuts for a simple mouth: it makes the LokutorLipSync for you.

## Your own names

**Mapping** says which of your shapes make each viseme, and how much of each:

```gdscript theme={null}
lips.mapping = {
    "aa": {"gape": 0.8},
    "oh": {"gape": 0.5, "kiss": 0.6},
    "PP": {"lips_closed": 1.0},
    "FF": {"lip_bite": 0.8},
}
lips.bind()          # after changing faces or mapping while the game runs
```

The viseme names are `Lokutor.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 a drawing

* **Jaw**: a `Node3D` rotated around its local X axis. Or **Skeleton** and **Jaw Bone** for a bone. `jaw_max_angle_degrees` is its widest. Jaws and blend shapes can be used together.
* **Sprite**: a `Sprite2D`, an `AnimatedSprite2D` or any node with a `frame`. Frames 0 to 3 are closed, slightly open, open and round. With other drawings, **Sprite Frames** gives the frame of each viseme: `{"sil": 0, "PP": 1, "aa": 2, "oh": 3}`.

For anything else read `mouth_open` (0 to 1), `current` (the strongest viseme) or `weights` (the 15 of them), or connect `viseme_changed`.

## The feel

| Property | Default | |
| :- | :- | :- |
| `intensity` | 1.0 | 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. |
| `stepped_fps` | 0 | Steps per second: 12 animates on twos, for a hand-drawn look. |

## Several voices, one mouth

A character can have a `LokutorAgent` for conversation and a `LokutorVoice` for [written lines](https://docs.lokutor.com/sdks/godot/speech.md) on the same LokutorLipSync. Each voice keeps its own visemes and the mouth follows whoever is speaking; stopping one does not close the mouth of the other.

## 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 `push_visemes()` with its visemes, if it has them, and `advance()` every frame with how much of it has been heard:

```gdscript theme={null}
func _process(delta: float) -> void:
    lips.advance($Recording.get_playback_position(), 0.3, $Recording.playing, delta)
```

## With moods and expressions

LokutorLipSync writes 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.