Gorilla.Audio.TTS.Visemes Unit Reference

Overview

The Gorilla.Audio.TTS.Visemes unit contains everything the lipsync of the text-to-speech subsystem is built from: the viseme set, the timeline of viseme keys and word markers, the phonemizer interface with its implementations, and the estimator that distributes phonemes over the amplitude envelope of the generated audio.

Class Hierarchy

TPersistent
  └── TGorillaVisemeTimeline

TInterfacedObject
  ├── TGorillaRuleBasedPhonemizer  (IGorillaPhonemizer)
  ├── TGorillaEspeakPhonemizer     (IGorillaPhonemizer)
  └── TGorillaEspeakLibPhonemizer  (IGorillaPhonemizer, in Gorilla.Audio.TTS.Espeak)

TGorillaVisemeEstimator (class with class methods only)

Enumerations

TGorillaVisemeKind

Viseme set as used by the Oculus/Meta LipSync and ARKit compatible character rigs. Most commercial and free character assets ship blend shapes with exactly these names.

Value Blend shape name Mouth shape
vkSilence sil Closed / neutral mouth, used for pauses
vkPP PP p, b, m — closed lips
vkFF FF f, v — lower lip at the upper teeth
vkTH TH th — tongue between the teeth
vkDD DD t, d — tongue at the alveolar ridge
vkKK kk k, g — back of the tongue
vkCH CH ch, sh, j — rounded and pushed forward
vkSS SS s, z — narrow teeth gap
vkNN nn n, l — tongue visible at the teeth
vkRR RR r — slightly rounded
vkAA aa a — wide open mouth
vkE E e — half open, spread
vkIH I i — narrow, spread
vkOH O o — rounded, open
vkOU U u — rounded, narrow

TGorillaMouthShape

Classic Preston Blair / Rhubarb mouth chart, useful for cartoon rigs and sprite based mouth animation: msA, msB, msC, msD, msE, msF, msG, msH, msX.

Types

TGorillaVisemeWeights = array[TGorillaVisemeKind] of Single;
TGorillaPhonemeArray  = TArray<TGorillaPhonemeItem>;

TGorillaVisemeWeights holds the weight of every viseme at a given point in time. The weights of a sample always add up to 1.0 and can be applied directly to morph targets.

Records

TGorillaPhonemeItem

A single phoneme of a phonemized word.

Field Description
Viseme Mouth shape this phoneme is rendered with
Phoneme Source symbol; IPA when a real phonemizer was used
Weight Relative duration weight — vowels are longer than plosives

TGorillaVisemeKey

A viseme and the time span it is active in.

Member Description
Start / End Time in seconds, relative to the utterance
WordIndex Index into the word list of the timeline, -1 for pauses
Duration() Length of the key
Contains(ATime) Whether a time falls into this key

TGorillaWordMarker

A spoken word and the time span it is audible in, with the same Duration() and Contains() helpers.

TGorillaVisemeTimeline

Ordered list of viseme keys and word markers of a single utterance.

Member Description
Clear() Drops all keys and words
AddKey(AKey) Appends a viseme key
AddKey(AStart, AEnd, AViseme, APhoneme, AWordIndex) Appends a key from its parts
AddWord(AStart, AEnd, AText) Appends a word marker
Sort() Sorts all keys by start time; called automatically by the estimator
Keys[AIndex] Viseme keys
KeyCount Number of keys
Words[AIndex] Word markers
WordCount Number of words
Duration Length of the utterance in seconds
BlendTime Cross fade between two visemes in seconds

Neighbouring keys sharing the same viseme are merged, which keeps the timeline small and the animation calm.

IGorillaPhonemizer

Backend independent interface turning text into phonemes.

Method Description
GetName() Human readable name
IsAvailable() False when the implementation cannot work, e.g. a missing library
PhonemizeWord(AWord, ALanguage) Phonemes of a single word
PhonemizeText(AText, ALanguage) Phonemes per word of a whole text

Implementations

Priority Class Unit Note
100 TGorillaEspeakLibPhonemizer Gorilla.Audio.TTS.Espeak espeak-ng library directly, real IPA, no process start
50 TGorillaEspeakPhonemizer this unit espeak-ng as a command line tool; Executable property, ResolveExecutable()
0 TGorillaRuleBasedPhonemizer this unit Grapheme approximation for DE/EN, always available

The first available implementation, by priority, wins. The library variant is architecture bound: the official espeak-ng binaries shipped with Piper are 64 bit, so a Win32 build falls back to the rule-based phonemizer.

TGorillaVisemeEstimator

Class Method Description
Estimate(AText, ALanguage, AEnvelope, AEnvelopeRate, ADuration, APhonemizer) Estimates the viseme timeline of an utterance

AEnvelope is the normalized amplitude envelope of the generated audio, as returned by GorillaExtractEnvelope() in Gorilla.Audio.TTS.Utils. It may be empty, in which case the phonemes are distributed evenly across the whole duration. APhonemizer may be nil to use the global default.

The estimator exists because Piper reports no phoneme times: the text is phonemized, each phoneme gets a class-dependent base duration, the speech sections are read out of the envelope, and the phoneme sequence is distributed over them — using the pauses as anchors, which keeps the mouth in sync even for long sentences.

Global Functions

Function Description
GorillaVisemeName(AViseme) Blend shape name of a viseme
GorillaVisemeByName(AName, ADefault) Viseme by blend shape name
GorillaVisemeToMouthShape(AViseme) Maps onto the Preston Blair chart
GorillaIPAToViseme(ASymbol, ...) Maps an IPA symbol onto a viseme
GorillaSplitWords(AText) Splits a text into words
GorillaDefaultPhonemizer() The phonemizer currently in use
GorillaRegisterPhonemizer(AValue, APriority) Registers an implementation
GorillaSetDefaultPhonemizer(AValue) Forces one implementation

Global Variables

Variable Description
GorillaEspeakExecutable Path to the espeak-ng executable used by TGorillaEspeakPhonemizer

Constants

Constant Value Description
GORILLA_VISEME_NAMES 'sil' 'PP' 'FF' 'TH' 'DD' 'kk' 'CH' 'SS' 'nn' 'RR' 'aa' 'E' 'I' 'O' 'U' Blend shape name per viseme
GORILLA_VISEME_BLENDTIME 0.045 Default cross fade between two visemes in seconds
GORILLA_VISEME_WEIGHTS — Relative duration weight per viseme

See Also