C API: Lip sync and voice mouths¶
Mouth shapes from audio, from timed phonemes or from text, and cheap mouths that move with a voice's loudness: Lip sync.
sona_lipsync_defaults¶
void sona_lipsync_defaults(sona_lipsync_options *o);
| Parameter and type | Meaning |
|---|---|
osona_lipsync_options * |
The sona_lipsync_options to fill with the defaults (required) |
Returns Nothing.
Example:
sona_lipsync_options x_lipsync_options;
memset(&x_lipsync_options, 0, sizeof x_lipsync_options);
x_lipsync_options.size = sizeof x_lipsync_options;
sona_lipsync_defaults(&x_lipsync_options);
size set; sample_rate 48000, channels 1, hold_seconds 0.07, attack_seconds 0.02, release_seconds 0.07, gate_db -55, lead_seconds 0.04.
sona_lipsync_create¶
sona_result sona_lipsync_create(const sona_lipsync_options *o,
const sona_allocator *al,
sona_lipsync **out);
| Parameter and type | Meaning |
|---|---|
oconst sona_lipsync_options * |
The options, a sona_lipsync_options (NULL: the defaults) |
alconst sona_allocator * |
A sona_allocator (required) |
outsona_lipsync ** |
Receives the new lip sync analyser (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).
NULL options: the defaults. al NULL: malloc. SONA_E_ARGUMENT for a size, rate, channel count, format or time out of range.
sona_lipsync_destroy¶
void sona_lipsync_destroy(sona_lipsync *ls);
| Parameter and type | Meaning |
|---|---|
lssona_lipsync * |
The lip sync analyser (required) |
Returns Nothing.
Example:
sona_lipsync_destroy(ls);
Frees the analyser.
sona_lipsync_reset¶
void sona_lipsync_reset(sona_lipsync *ls);
| Parameter and type | Meaning |
|---|---|
lssona_lipsync * |
The lip sync analyser (required) |
Returns Nothing.
Example:
sona_lipsync_reset(ls);
Back to time 0: hints and frames waiting to be read are dropped.
sona_lipsync_feed¶
sona_result sona_lipsync_feed(sona_lipsync *ls, const void *pcm,
size_t frames);
| Parameter and type | Meaning |
|---|---|
lssona_lipsync * |
The lip sync analyser (required) |
pcmconst void * |
Audio samples, interleaved, in the format the options name (required) |
framessize_t |
How many sample frames pcm holds |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
frames: samples per channel. Analyses every 10 ms that is complete.
sona_lipsync_read¶
uint32_t sona_lipsync_read(sona_lipsync *ls, sona_lipsync_frame *out,
uint32_t max);
| Parameter and type | Meaning |
|---|---|
lssona_lipsync * |
The lip sync analyser (required) |
outsona_lipsync_frame * |
Receives the sona_lipsync_frame (required) |
maxuint32_t |
How many entries out holds |
Returns uint32_t.
Example:
sona_lipsync_frame x_lipsync_frame;
memset(&x_lipsync_frame, 0, sizeof x_lipsync_frame);
uint32_t x_got = sona_lipsync_read(ls, &x_lipsync_frame, 1);
printf("sona_lipsync_read: %lld\n", (long long)x_got);
Moves up to max frames made since the last read into out, oldest first; returns how many.
sona_lipsync_current¶
sona_result sona_lipsync_current(const sona_lipsync *ls,
sona_lipsync_frame *out);
| Parameter and type | Meaning |
|---|---|
lsconst sona_lipsync * |
The lip sync analyser (required) |
outsona_lipsync_frame * |
Receives the sona_lipsync_frame (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Example:
sona_lipsync_frame x_lipsync_frame;
memset(&x_lipsync_frame, 0, sizeof x_lipsync_frame);
sona_result result = sona_lipsync_current(ls, &x_lipsync_frame);
if (result != SONA_OK) printf("sona_lipsync_current: %s\n",
sona_result_name(result));
The newest frame (a shut mouth before the first).
sona_lipsync_latency¶
double sona_lipsync_latency(const sona_lipsync *ls);
| Parameter and type | Meaning |
|---|---|
lsconst sona_lipsync * |
The lip sync analyser (required) |
Returns double.
Example:
double x_got = sona_lipsync_latency(ls);
printf("sona_lipsync_latency: %g\n", (double)x_got);
Seconds from a sample being fed to the first frame that hears it.
sona_lipsync_hint¶
sona_result sona_lipsync_hint(sona_lipsync *ls, const sona_phoneme *ph,
uint32_t count);
| Parameter and type | Meaning |
|---|---|
lssona_lipsync * |
The lip sync analyser (required) |
phconst sona_phoneme * |
A sona_phoneme (required) |
countuint32_t |
How many entries the array holds |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Example:
sona_phoneme x_phoneme;
memset(&x_phoneme, 0, sizeof x_phoneme);
sona_result result = sona_lipsync_hint(ls, &x_phoneme, 1);
if (result != SONA_OK) printf("sona_lipsync_hint: %s\n",
sona_result_name(result));
Phonemes the host's TTS reported, on the fed audio's clock: their shapes win while the audio is sounding, and lips close for M, B and P. Up to 256 held; ones that ended a second ago go.
sona_phoneme_mouth¶
uint32_t sona_phoneme_mouth(const char *symbol);
| Parameter and type | Meaning |
|---|---|
symbolconst char * |
A phoneme symbol (required) |
Returns uint32_t.
Example:
uint32_t x_got = sona_phoneme_mouth("example");
printf("sona_phoneme_mouth: %lld\n", (long long)x_got);
The mouth for a phoneme symbol; SONA_MOUTH_UNKNOWN when it is none of the sets.
sona_lipsync_phonemes¶
sona_result sona_lipsync_phonemes(const sona_phoneme *ph, uint32_t count,
const sona_lipsync_options *o,
sona_mouth_key *out, uint32_t cap,
uint32_t *total);
| Parameter and type | Meaning |
|---|---|
phconst sona_phoneme * |
A sona_phoneme (required) |
countuint32_t |
How many entries the array holds |
oconst sona_lipsync_options * |
The options, a sona_lipsync_options (required) |
outsona_mouth_key * |
Receives the sona_mouth_key (required) |
capuint32_t |
How many entries out holds |
totaluint32_t * |
Receives how many there are in all; may be NULL (NULL: not written) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).
Timed phonemes to keys (lead, closures kept, short shapes merged). *total is the count; writes up to cap. o may be NULL.
sona_lipsync_text¶
sona_result sona_lipsync_text(const char *text, const void *pcm,
size_t frames, const sona_lipsync_options *o,
sona_mouth_key *out, uint32_t cap,
uint32_t *total);
| Parameter and type | Meaning |
|---|---|
textconst char * |
The text to read (required) |
pcmconst void * |
Audio samples, interleaved, in the format the options name (required) |
framessize_t |
How many sample frames pcm holds |
oconst sona_lipsync_options * |
The options, a sona_lipsync_options (required) |
outsona_mouth_key * |
Receives the sona_mouth_key (required) |
capuint32_t |
How many entries out holds |
totaluint32_t * |
Receives how many there are in all; may be NULL (NULL: not written) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_LIMIT, SONA_E_MEMORY (what each means).
Text to keys. With audio (frames > 0, in o's format) the text is aligned to it; without, an even pace. SONA_E_LIMIT past 4096 letters or the 10 minutes limit of audio.
sona_mouth_keys_sample¶
sona_result sona_mouth_keys_sample(const sona_mouth_key *keys,
uint32_t count, double t,
sona_lipsync_frame *out);
| Parameter and type | Meaning |
|---|---|
keysconst sona_mouth_key * |
A sona_mouth_key (required) |
countuint32_t |
How many entries the array holds |
tdouble |
The time to sample, seconds |
outsona_lipsync_frame * |
Receives the sona_lipsync_frame (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Example:
sona_mouth_key x_mouth_key;
memset(&x_mouth_key, 0, sizeof x_mouth_key);
sona_lipsync_frame x_lipsync_frame2;
memset(&x_lipsync_frame2, 0, sizeof x_lipsync_frame2);
sona_result result = sona_mouth_keys_sample(&x_mouth_key, 1, 0.5f,
&x_lipsync_frame2);
if (result != SONA_OK) printf("sona_mouth_keys_sample: %s\n",
sona_result_name(result));
The mouth at time t of a key list, eased between keys.
sona_avatar_mouth¶
sona_result sona_avatar_mouth(sona_avatar *a, uint32_t shape);
| Parameter and type | Meaning |
|---|---|
asona_avatar * |
The avatar (required) |
shapeuint32_t |
A SONA_MOUTH_* shape |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED (what each means).
Example:
sona_result result = sona_avatar_mouth(avatar, 0);
if (result != SONA_OK) printf("sona_avatar_mouth: %s\n",
sona_result_name(result));
Only the mouth of the expression: a SONA_MOUTH_* or another shape index, or 255 to hand it back to the clip. The rest of the face keeps what sona_avatar_expression or the clip gave it. The same shape again does nothing.
sona_voice_mouth_init¶
void sona_voice_mouth_init(sona_voice_mouth *v, uint32_t seed);
| Parameter and type | Meaning |
|---|---|
vsona_voice_mouth * |
Receives the sona_voice_mouth (required) |
seeduint32_t |
The seed: the same seed gives the same result |
Returns Nothing.
Example (also in Lip sync: a microphone or any audio drives the mouth):
sona_voice_mouth v[64];
for (i = 0; i < n; i++) sona_voice_mouth_init(&v[i],
sona_avatar_id(avatars[i]));
/* each frame: */
uint32_t changed = sona_voice_mouths(avatars, v, levels, n, dt);
Sets size and starts the state from seed. Avatars with different seeds move their mouths differently to the same voice.
sona_voice_mouth_step¶
uint32_t sona_voice_mouth_step(sona_voice_mouth *v, float level, float dt,
float *open);
| Parameter and type | Meaning |
|---|---|
vsona_voice_mouth * |
Receives the sona_voice_mouth (required) |
levelfloat |
The audio level, linear RMS |
dtfloat |
Seconds since the last call |
openfloat * |
Receives how open the mouth is, 0 to 1 (required) |
Returns uint32_t.
Advances by dt seconds; returns the SONA_MOUTH_* to show. open may be NULL.
sona_avatar_voice¶
sona_result sona_avatar_voice(sona_avatar *a, sona_voice_mouth *v,
float level, float dt);
| Parameter and type | Meaning |
|---|---|
asona_avatar * |
The avatar (required) |
vsona_voice_mouth * |
Receives the sona_voice_mouth (required) |
levelfloat |
The audio level, linear RMS |
dtfloat |
Seconds since the last call |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_DESTROYED (what each means).
Example:
sona_voice_mouth x_voice_mouth;
memset(&x_voice_mouth, 0, sizeof x_voice_mouth);
x_voice_mouth.size = sizeof x_voice_mouth;
sona_result result = sona_avatar_voice(avatar, &x_voice_mouth, 0,
1.0f / 60);
if (result != SONA_OK) printf("sona_avatar_voice: %s\n",
sona_result_name(result));
sona_voice_mouth_step with the voice's level, put on the avatar's mouth with sona_avatar_mouth.
sona_voice_mouths¶
uint32_t sona_voice_mouths(sona_avatar *const *avatars,
sona_voice_mouth *states, const float *levels,
uint32_t count, float dt);
| Parameter and type | Meaning |
|---|---|
avatarssona_avatar *const * |
The avatars, count of them (required) |
statessona_voice_mouth * |
A mouth state per avatar (required) |
levelsconst float * |
An audio level per avatar, linear RMS (required) |
countuint32_t |
How many entries the array holds |
dtfloat |
Seconds since the last call |
Returns uint32_t.
Example (also in Lip sync: a microphone or any audio drives the mouth):
sona_voice_mouth v[64];
for (i = 0; i < n; i++) sona_voice_mouth_init(&v[i],
sona_avatar_id(avatars[i]));
/* each frame: */
uint32_t changed = sona_voice_mouths(avatars, v, levels, n, dt);
sona_avatar_voice for count avatars (NULL entries skipped); returns how many mouths changed.
This page as Markdown · All the docs as one file (llms-full.txt)