For the complete documentation index, see llms.txt. This page is also available as Markdown.

Add lip sync in vanilla TypeScript

Play the facial animation frames that the Convai Web SDK streams with a character's voice on a 3D model in plain TypeScript, without a UI framework.

Drive a three.js character's morph targets from the blendshape frames that Convai streams alongside the character's voice. Use this page when you render the character yourself in framework-free TypeScript. At the end, the character's mouth moves in time with its speech and settles to neutral when it stops or is interrupted.

Prerequisites

Enable lip sync

Set enableLipsync: true and choose the frame format in blendshapeConfig.format: 'mha' (251 MetaHuman channels, the default) or 'arkit' (61 values).

import { ConvaiClient } from '@convai/web-sdk/vanilla';

const client = new ConvaiClient({
  apiKey: 'YOUR_API_KEY',
  characterId: 'YOUR_CHARACTER_ID',
  enableLipsync: true,
  blendshapeConfig: { format: 'arkit' },
});

await client.connect();

Without enableLipsync: true, Convai sends no frames and the queue stays empty. Frames arrive in chunks and the SDK buffers them in client.blendshapeQueue.

Bind the morph targets

Build a lookup from frame index to morph target slot once, after the model loads. The frame order is ARKIT_ORDER_61 for 'arkit' and METAHUMAN_ORDER_251 for 'mha'.

The last nine 'arkit' values are head and eye rotations, not morph targets. They find no slot and are skipped.

Play the frames

Run a requestAnimationFrame loop that advances a clock while the character speaks, plays the frame for that time, and consumes the frames it has passed. Read the frame with getFrameWithAlpha, which fades the face in over the first 10 frames of a turn and out over the last 10.

The loop never pairs getFrameAtTime() with consumeFrames(). getFrameAtTime() indexes from the front of the queue, so consuming frames after it advances playback twice. Use one of the two approaches, not both.

The client itself starts each turn on the queue when you send a message, fire a trigger, or the user starts speaking, and clears it when you call sendInterruptMessage(). Your loop only reads and consumes.

Remap channels with a mapper

To translate frames into your rig's own layout as they enter the queue, set a mapper. A mapper receives each raw frame and returns a Float32Array. Pass it as blendshapeConfig.customMapper, or set it on a live queue:

With a mapper set, frames no longer follow ARKIT_ORDER_61 or METAHUMAN_ORDER_251, so bind your slots to the mapper's output layout instead.

Verify lip sync

Send a message and listen to the reply. The mouth moves while the character speaks and returns to neutral after the last word. Call sendInterruptMessage() mid-reply: the face settles at once instead of freezing on the last shape. For a snapshot of the queue while debugging, log queue.getDebugInfo().

Next steps

Drive facial animation with blendshapesApply MetaHuman limit driversConvaiClient reference

Last updated

Was this helpful?