Gorilla.Audio.TTS.Speaker Unit Reference
Overview
The Gorilla.Audio.TTS.Speaker unit contains the component applications work
with: TGorillaTextToSpeech, its collection of TGorillaTTSSpeaker characters,
the utterance objects travelling from text to audible speech, the speech cache
and the synthesis worker thread.
Class Hierarchy
TFmxObject
└── TGorillaTextToSpeech
TOwnedCollection
└── TGorillaTTSSpeakers
TCollectionItem
└── TGorillaTTSSpeaker
TObject
├── TGorillaTTSUtterance
└── TGorillaTTSCache
Enumerations
TGorillaTTSUtteranceState
Lifecycle of a single spoken sentence.
| Value |
Description |
usPending |
Queued, waiting for the worker thread |
usSynthesizing |
The engine is generating the audio |
usReady |
Audio is available and waits for its turn |
usPlaying |
Currently audible |
usFinished |
Playback completed |
usFailed |
Synthesis or playback failed, see Error |
usCancelled |
Dropped before it became audible |
Event Types
TGorillaSpeechEvent = procedure(ASender : TObject;
const ASpeaker : TGorillaTTSSpeaker;
const AUtterance : TGorillaTTSUtterance) of object;
TGorillaSpeechErrorEvent = procedure(ASender : TObject;
const ASpeaker : TGorillaTTSSpeaker;
const AUtterance : TGorillaTTSUtterance; const AError : String) of object;
TGorillaVisemeEvent = procedure(ASender : TObject;
const ASpeaker : TGorillaTTSSpeaker; const AViseme : TGorillaVisemeKind;
const AWeights : TGorillaVisemeWeights) of object;
TGorillaSpeechWordEvent = procedure(ASender : TObject;
const ASpeaker : TGorillaTTSSpeaker; const AWordIndex : Integer;
const AWord : String) of object;
TGorillaTTSUtterance
One sentence on its way from text to audible speech. Instances are owned by
TGorillaTextToSpeech and released once they finished — never keep a
reference beyond the event they were reported in.
| Property |
Type |
Description |
Id |
Cardinal |
Unique number identifying this utterance |
Speaker |
TGorillaTTSSpeaker |
The character it belongs to |
Text |
String |
The spoken text |
State |
TGorillaTTSUtteranceState |
Current lifecycle state |
Error |
String |
Reason of a failure, empty otherwise |
Duration |
Single |
Length of the generated audio in seconds |
Visemes |
TGorillaVisemeTimeline |
Lipsync data, nil until the synthesis finished |
Result |
TGorillaTTSResult |
Audio and lipsync data |
Request |
TGorillaTTSRequest |
The request handed to the engine |
CacheKey |
String |
Key this utterance is cached under |
Tag |
NativeInt |
Free for application use |
TGorillaTTSSpeaker
A talking character: voice settings, the 3D object the voice is emitted from,
and the queue of sentences still to speak.
Public Methods
| Method |
Description |
Speak(AText) |
Queues a sentence, returns the utterance id or 0 when the speaker is disabled or the text is empty. Returns immediately, synthesis happens in the background |
Stop() |
Stops the current sentence and clears the queue |
Pause() |
Pauses the current sentence |
Resume() |
Continues a paused sentence |
Public Properties
| Property |
Type |
Description |
TTS |
TGorillaTextToSpeech |
The owning component |
Current |
TGorillaTTSUtterance |
The sentence currently played, nil when silent |
IsSpeaking |
Boolean |
True while a sentence is audible |
QueueLength |
Integer |
Sentences waiting to be spoken |
PlaybackTime |
Single |
Position inside the current sentence in seconds |
Viseme |
TGorillaVisemeKind |
Dominant viseme at the current position |
VisemeWeights |
TGorillaVisemeWeights |
Blended weight of every viseme, ready for morph targets |
VisemeWeight[AViseme] |
Single |
Weight of a single viseme, 0..1 |
WordIndex |
Integer |
Index of the word currently spoken, -1 between words |
SoundDebugPosition |
UInt32 |
Position reported by the audio backend, diagnostic |
SoundDebugPlaying |
Boolean |
Playback state of the audio backend, diagnostic |
Offset |
TPoint3D |
Mouth offset relative to the target's origin |
Published Properties
| Property |
Type |
Default |
Description |
Name |
String |
— |
The name the character is addressed by |
VoiceId |
String |
— |
Piper model name or path; empty uses the engine default |
SpeakerId |
Integer |
-1 |
Speaker index inside a multi-speaker model |
Language |
String |
— |
Language of the spoken text, drives phonemization |
Rate |
Single |
1.0 |
Speaking rate, 1.2 speaks 20 % faster |
Pitch |
Single |
1.0 |
Playback pitch — useful to derive several characters from one voice model |
Volume |
Single |
— |
Playback gain, 0..1 |
Expressiveness |
Single |
— |
Variation in the generated voice, 0..1 |
SentenceSilence |
Single |
— |
Pause between two sentences in seconds |
Enabled |
Boolean |
True |
A disabled speaker silently drops every Speak() |
Spatial |
Boolean |
True |
Plays the voice at the position of Target instead of centred |
Interrupt |
Boolean |
False |
A new sentence cuts off the running one instead of queueing |
MinDistance |
Single |
— |
Distance the voice starts to get quieter at |
MaxDistance |
Single |
— |
Distance the voice is completely faded out at |
Target |
TControl3D |
— |
The 3D object the voice is emitted from |
Events
| Event |
Fired when |
OnSpeechStart |
A sentence became audible |
OnSpeechFinished |
A sentence finished playing |
OnViseme |
The dominant mouth shape changed |
OnWord |
The spoken word changed, e.g. for subtitles |
OnError |
A sentence could not be spoken |
TGorillaTTSSpeakers
Owned collection of all characters a component speaks for.
| Member |
Description |
Add() |
Creates a new speaker |
FindByName(AName) |
Speaker by name, nil when unknown |
Items[AIndex] |
Typed default indexer |
TGorillaTextToSpeech
Public Methods
| Method |
Description |
ActiveEngine() |
The engine actually used; creates one of type EngineName when no component was assigned |
ActiveAudioManager() |
The audio manager actually used; falls back to the first manager next to this component |
AddSpeaker(AName, AVoiceId) |
Creates a new character |
FindSpeaker(AName) |
Character by name, nil when unknown |
Speak(ASpeakerName, AText) |
Queues a sentence, returns the utterance id or 0 for an unknown character |
Speak(ASpeaker, AText) |
Same for an already resolved character |
StopAll() |
Stops every character and clears all queues |
Update() |
Advances playback and lipsync of all characters |
ClearCache() |
Empties the speech cache |
PurgeCache() |
Empties it including its files on disk |
GetVoices() |
Lists the voices the current engine offers |
| Property |
Description |
Cache |
Direct access to the speech cache |
Published Properties
| Property |
Type |
Default |
Description |
Engine |
TGorillaTTSEngine |
— |
Engine component doing the synthesis |
EngineName |
String |
— |
Engine created internally when Engine is empty; empty picks the first backend, e.g. Piper |
AudioManager |
TGorillaAudioManager |
— |
Manager used for playback; empty uses the first manager owned by the same form |
Speakers |
TGorillaTTSSpeakers |
— |
The characters this component speaks for |
Active |
Boolean |
True |
Starts and stops the synthesis worker |
AutoUpdate |
Boolean |
True |
Drives Update() from an internal timer |
UpdateInterval |
Integer |
16 |
Interval of that timer in ms |
CacheEnabled |
Boolean |
True |
Reuses the audio of sentences spoken before |
CacheDirectory |
String |
— |
Folder the cache persists its wave files in; empty = memory only |
CacheCapacity |
Integer |
64 |
Sentences kept in the memory cache |
DefaultLanguage |
String |
— |
Language for speakers that do not define their own |
Events
Same set as the speaker, but raised for every character:
OnSpeechStart, OnSpeechFinished, OnViseme, OnWord, OnError.
Constants
| Constant |
Value |
Description |
GORILLA_TTS_CACHE_CAPACITY |
64 |
Sentences the memory cache keeps by default |
See Also