Gorilla.Audio.TTS Unit Reference
Overview
The Gorilla.Audio.TTS unit defines the backend independent core of the
text-to-speech subsystem: the synthesis request, the result carrying audio and
lipsync data, the abstract TGorillaTTSEngine, and the registry that makes
backends selectable by name.
Class Hierarchy
TPersistent
└── TGorillaTTSResult
TFmxObject
└── TGorillaTTSEngine (abstract)
└── TGorillaPiperEngine (Gorilla.Audio.TTS.Piper)
TGorillaTTSEngineRegistry (class with class methods only)
Types
TGorillaTTSAudioFormat = TGorillaWaveFormat; // from Gorilla.Audio.TTS.Utils
TGorillaTTSVoices = TArray<TGorillaTTSVoice>;
TGorillaTTSEngineClass = class of TGorillaTTSEngine;
Records
TGorillaTTSVoice
Describes a voice an engine is able to speak with.
| Field |
Type |
Description |
Id |
String |
Engine specific identifier; Piper uses the path of the .onnx model |
Name |
String |
Human readable name, shown in editors and drop-downs |
Language |
String |
Language code, e.g. de_DE |
SpeakerId |
Integer |
Speaker index inside a multi-speaker model, -1 = default |
SampleRate |
Integer |
Native sample rate of the voice |
| Method |
Description |
Create(AId, AName, ALanguage, ASpeakerId, ASampleRate) |
Constructor |
DisplayName() |
Name including the speaker id where relevant |
TGorillaTTSRequest
Everything an engine needs to synthesize a single utterance.
| Field |
Type |
Description |
Text |
String |
The text to speak |
VoiceId |
String |
Voice identifier; empty uses the engine's default voice |
SpeakerId |
Integer |
Speaker index in a multi-speaker model, -1 = default |
Language |
String |
Language of the text, used for phonemization |
Rate |
Single |
Speaking rate, 1.0 normal, above speaks faster |
Expressiveness |
Single |
Variation of the generated voice, 0..1; Piper maps it onto its noise scale parameters |
SentenceSilence |
Single |
Pause between two sentences in seconds |
| Method |
Description |
Create(AText, AVoiceId) |
Constructor with defaults |
CacheKey(AEngineName) |
Stable key identifying the synthesis result; playback-only settings such as volume or pitch are not part of it |
TGorillaTTSResult
The audio and lipsync data an engine produced for one utterance.
Properties
| Property |
Type |
Description |
Wave |
TMemoryStream |
Complete RIFF/WAVE data of the utterance |
Visemes |
TGorillaVisemeTimeline |
Viseme timeline used for lipsync, may be empty |
Format |
TGorillaTTSAudioFormat |
Sample format of the wave data |
Duration |
Single |
Playback duration in seconds |
Text |
String |
The spoken text |
EngineName |
String |
Engine that produced the result |
VoiceId |
String |
Voice the result was spoken with |
IsValid |
Boolean |
True when the result carries usable audio |
Methods
| Method |
Description |
Clear() |
Drops audio and timeline |
SetWave(AStream) |
Takes ownership of a RIFF/WAVE stream and refreshes format and duration from its header |
SaveToFile(AFilename) |
Writes audio and timeline to disk |
LoadFromFile(AFilename) |
Reads them back |
Assign(ASource) |
Standard TPersistent assignment |
TGorillaTTSEngine
Abstract base class of all text-to-speech backends. Synthesize() is called
from a worker thread of TGorillaTextToSpeech; a backend that cannot work in
parallel overrides IsThreadSafe() and returns false, in which case the caller
serializes all requests.
Class Methods
| Method |
Description |
GetEngineName() |
Unique name of the backend, used by the registry and by EngineName (abstract) |
IsSupported() |
False when the backend can never work on the current platform |
Public Methods
| Method |
Description |
IsAvailable() |
True when the backend is completely configured and ready |
IsThreadSafe() |
False when the backend must not be called from several threads |
GetVoices() |
The voices this engine offers |
FindVoice(AIdOrName, ...) |
Resolves a voice by id or name |
Synthesize(ARequest) |
Synthesizes an utterance; the caller owns the result, nil on failure |
Synthesize(AText, AVoiceId) |
Convenience overload |
| Property |
Description |
LastError |
Reason of the last failed operation |
Published Properties
| Property |
Type |
Default |
Description |
DefaultVoice |
String |
— |
Voice used when a request does not name one |
DefaultLanguage |
String |
— |
Language used when a request does not name one |
Lipsync |
Boolean |
True |
Builds the viseme timeline after the synthesis |
Protected Methods (for implementers)
| Method |
Description |
DoSynthesize(ARequest, AResult) |
Produces the audio; must fill AResult.Wave and AResult.Format (abstract) |
BuildLipsync(ARequest, AResult) |
Estimates the viseme timeline; skipped when the backend filled AResult.Visemes itself |
SetError(AMessage) |
Stores an error message and returns false |
TGorillaTTSEngineRegistry
Registry of all available synthesis backends. Backends register themselves in
the initialization section of their unit, so adding the unit to a project makes
the engine selectable by name at design-time and at runtime.
| Class Method |
Description |
RegisterEngine(AClass) |
Registers a backend |
UnregisterEngine(AClass) |
Removes it again |
FindEngineClass(AName) |
Resolves a backend class by engine name |
CreateEngine(AName, AOwner) |
Creates an instance; an empty name picks the first supported backend |
EngineNames() |
Names of all registered backends |
DefaultEngineName() |
Name of the first backend supported on this platform |
Constants
| Constant |
Value |
Description |
GORILLA_TTS_NEUTRAL |
1.0 |
Neutral value for rate and pitch |
GORILLA_TTS_SENTENCE_SILENCE |
0.2 |
Default pause between sentences in seconds |
See Also