A lip-sync model in 0.88 million parameters of plain JavaScript Stork Live's browser-drawn talking avatar runs on a lip-sync model of 0.88 million parameters written in plain JavaScript, with no ML runtime, according to the company's technical post. The model converts 16 kHz speech into 16 mouth controls at 25 frames per second, hearing 155 ms past each output frame, and scored 0.71 correlation against MediaPipe-tracked lip opening on 18 held-out clips (nine human readers, nine synthetic voices), against a roughly 0.90 self-agreement ceiling for the video model that generated the labels. Stork Live trained the small model by distilling labels from a slower server-side model over about five hours of speech — fourteen public-domain audiobook recordings plus synthetic voices — and said size and look-ahead barely moved the score, so it chose the fastest variant. Stork Live https://www.stork.ai/live is a talking avatar that the visitor's browser draws. For that to cost nothing per minute, the lip movement has to be worked out on the visitor's device too. This post is about the model that does it. The code is in the open client https://github.com/jupiterspins/stork-live/blob/main/src/local-motion.js . What it has to produce what-it-has-to-produce The avatar's mouth is set by 16 numbers per video frame, at 25 frames a second. The model's whole job is to turn 16 kHz speech into those numbers, a fraction of a second behind the sound. Make one free https://www.stork.ai/tools/talking-photo?utm source=house ad&utm medium=inline&utm campaign=talk-photo Developers: there is an API https://www.stork.ai/developers/talking-head-api?utm source=house ad&utm medium=inline&utm campaign=talk-photo-second The network the-network | Stage | Detail | |---|---| | Input | 80-band log-mel spectrogram, one frame every 10 ms | | Two convolutions | Kernel 4, stride 2 each: 100 frames a second become 25 | | Two GRU layers | 256 units each, running forwards only | | Output | 16 mouth controls, for the frame 80 ms behind the newest | Each mel frame covers 25 ms of sound and nothing ahead of it. Counting the convolutions and the output delay, the model has heard 155 ms past the frame it is producing. How it was trained how-it-was-trained We had no large set of video with mouth controls. We had a slower, server-side model that produces them from sound. So that model labelled about five hours of speech: fourteen public-domain audiobook recordings and a set of synthetic voices. The small model learned to reproduce its labels. Three things mattered: - Weighting by what is visible. The first mouth control moves the face about 35 times as far as the sixteenth. The loss weights each control by how far it moves the face. - Loudness variety. Each training clip is played at a random level between a fifth and a little over twice its own, with a little noise added. Without this, a quiet microphone would look like silence. - A gain on the output. A model trained to match an average comes out quieter than the thing it averages. One multiplier per control, measured on held-out speech, restores the range. Enjoying this? Get one like it in your inbox each morning. one email a day · unsubscribe in two clicks · no third-party tracking How we know it works how-we-know-it-works We scored it on 18 clips it had never heard: nine human readers and nine synthetic voices. The score is the correlation between the model's lip gap and the lip opening tracked by MediaPipe in video rendered from the same speech, averaged over the clips. | Variant | Parameters | Hears ahead | Score | |---|---|---|---| | Chosen | 0.88 M | 155 ms | 0.71 | | Same, hearing further | 0.88 M | 195 ms | 0.70 | | Same, further still | 0.88 M | 275 ms | 0.71 | | Same, much further | 0.88 M | 395 ms | 0.69 | | Smaller GRU | 0.36 M | 195 ms | 0.69 | | Larger | 1.89 M | 195 ms | 0.71 | The video model the clips came from agrees with itself at about 0.90 when it renders the same speech twice, so that is the ceiling. Size and look-ahead barely moved the score. That told us to pick the fastest, and that the remaining gap is in the training labels, not in the small model. Why no ML runtime why-no-ml-runtime The whole forward pass is a few hundred lines: a 512-point FFT, 80 mel filters, two convolutions, two GRU steps and a matrix product, 25 times a second. An ML runtime would add megabytes of download to save milliseconds we do not need. It also means the model is readable. Anyone can open the file and see what it does to their audio. Nothing leaves the device. The check that caught our own mistake the-check-that-caught-our-own-mistake We compare the JavaScript output with PyTorch on a test sentence, fed in 1,024-sample pieces as a microphone would deliver it. The first run was off by a large margin. The model was right. The test was reading the audio file from the wrong byte, because the file's header was longer than the usual 44 bytes. With that fixed, the largest difference across 221 frames was 0.000004. Limits limits - The training speech was English. The lips move with other languages, a step less accurately. We have not trained on them yet. - The score measures how far the lips open, not every mouth shape. - It follows whatever sound it hears, including music or a second voice in the background. To hear it on your own voice, open the Stork Live page https://www.stork.ai/live and press "Use my microphone".