Speech-to-Text (STT)
Voice input: microphone in, recognized text and voice commands out.
TGorillaSpeechToText records through the audio driver already present in your
scene, cuts the stream into utterances, hands them to a recognizer on a worker
thread and raises the result on the main thread.
The recognition engines are not part of the Gorilla3D distribution. whisper.cpp and Vosk — their libraries, executables and models — are downloaded separately, see Getting whisper.cpp and Getting Vosk.
Table of Contents
- Architecture
- Units
- Choosing an Engine
- Getting whisper.cpp
- Getting Vosk
- Setting up the Component
- Listening Modes
- Voice Commands
- Results
- Voice Activity Detection
- Capture Devices
- Testing without a Microphone
- Events
- Platform Support
- Troubleshooting
- Best Practices
- See Also
Architecture
microphone
|
IGorillaAudioCapture capture backend (OpenAL / FMOD)
|
IGorillaVAD voice activity detection, cuts out utterances
|
TGorillaSTTEngine recognition (whisper.cpp / Vosk)
|
TGorillaSpeechToText queue, events, voice command matching
Two threads are involved: a capture thread that drains the recording device at a
raised priority — a device that is not drained in time silently overwrites its
own ring buffer — and a worker thread doing the recognition. Events are queued
and raised by Update() on the main thread, so a handler may safely touch the
scene.
Units
| Unit | Content |
|---|---|
Gorilla.Audio.STT |
Request, result, abstract TGorillaSTTEngine, engine registry |
Gorilla.Audio.STT.Listener |
TGorillaSpeechToText, voice commands, threads |
Gorilla.Audio.STT.Capture |
IGorillaAudioCapture plus the OpenAL, FMOD and null backends |
Gorilla.Audio.STT.VAD |
IGorillaVAD, the energy based detector and the registry |
Gorilla.Audio.STT.Whisper |
whisper.cpp backend (library or command line) |
Gorilla.Audio.STT.Vosk |
Vosk backend (streaming, grammar capable) |
Gorilla.Audio.STT.Utils |
Sample buffers, resampling, wave file helpers |
Choosing an Engine
| whisper.cpp | Vosk | |
|---|---|---|
| Engine name | Whisper |
Vosk |
| Accuracy | Very high | Good |
| Streaming / partial results | No | Yes |
| Grammar (restrict to phrases) | No (uses the phrases as a prompt) | Yes |
| Language auto detection | Yes | No — one model per language |
| Word timings | Yes | Yes |
| Latency | Recognizes after the utterance ended | Reports while the user is still speaking |
| Model size | 75 MB (tiny) … 3 GB (large) | 50 MB (small) … 2 GB |
Rule of thumb: Vosk for voice commands that have to react immediately, whisper.cpp when the text itself matters — dictation, subtitles, free-form input. The listener component works with both, so this is a one-property decision.
Getting whisper.cpp
whisper.cpp is a local implementation of OpenAI's Whisper model — no cloud, no account. You need two things: the binaries and a model file.
1. Binaries
| Source | |
|---|---|
| Project | https://github.com/ggml-org/whisper.cpp |
| Releases | https://github.com/ggml-org/whisper.cpp/releases |
The engine can use either of two paths, controlled by Mode:
| Mode | What it needs |
|---|---|
wmLibrary |
The shared library whisper.dll (Windows), libwhisper.so / libwhisper.so.1 (Linux), libwhisper.dylib (macOS) |
wmProcess |
The command line tool whisper-cli (older builds: main) |
wmAuto |
Library when it loads, otherwise the command line tool — the default |
The release archives contain both. Put them next to your application or
somewhere on the system library / search path; LibraryPath and
ExecutablePath override the search when you keep them elsewhere.
2. Model files
| Source | |
|---|---|
| GGML models | https://huggingface.co/ggerganov/whisper.cpp/tree/main |
| Download script | models/download-ggml-model.sh in the whisper.cpp repository |
Models are single files named ggml-<size>.bin:
| File | Size | Note |
|---|---|---|
ggml-tiny.bin |
~75 MB | Fast, noticeably weaker |
ggml-base.bin |
~142 MB | Good compromise for voice commands |
ggml-small.bin |
~466 MB | Clearly better for free text |
ggml-medium.bin |
~1.5 GB | |
ggml-large-v3.bin |
~3 GB | Best quality, slowest |
The .en variants (ggml-base.en.bin) are English-only and better at English
than their multilingual counterpart of the same size.
Point the engine at them:
LWhisper.ModelDirectory := 'C:\tools\whisper\models'; // scanned for ggml-*.bin
LWhisper.ModelPath := 'base'; // -> ggml-base.bin
ModelPath accepts an absolute path, a file name inside ModelDirectory, or a
bare size name such as base or small.en. RefreshModels() rescans the
folder, GetModels() returns what was found, and LibraryAvailable() /
ResolveExecutable() tell you what the engine would actually use.
Whisper engine properties
| Property | Default | Description |
|---|---|---|
Mode |
wmAuto |
How whisper.cpp is reached |
LibraryPath |
— | Path of the shared library |
ExecutablePath |
— | Path of whisper-cli |
ModelPath |
— | Model to recognize with |
ModelDirectory |
— | Folder scanned for ggml-*.bin |
CommandTemplate |
see below | Command line used in wmProcess |
Threads |
0 | 0 uses half the cores, leaving room for the render loop |
Timeout |
60000 | Milliseconds a single recognition may take |
UseGPU |
False | Only with a GPU build of the library |
MaxSegmentLength |
0 | Characters per segment, 0 = no limit (useful for subtitles) |
SplitOnWord |
True | Keeps words intact when splitting |
Temperature |
— | 0 is deterministic, the right choice for voice commands |
NoSpeechThreshold |
— | Probability above which a segment is discarded as silence |
Command line placeholders: %EXE%, %MODEL%, %INPUT%, %OUTPUT%,
%LANGUAGE%, %THREADS%, %TRANSLATE%, %PROMPT%, %JSONFULL%.
UseGPU is off by default on purpose: a Vulkan build of whisper.cpp shares the
device with the Gorilla3D Vulkan renderer, and whether that is collision free is
unverified.
Licensing
whisper.cpp is MIT licensed, the models are released by OpenAI under MIT as well. You still distribute them yourself — Gorilla3D ships neither.
Getting Vosk
Vosk is a streaming recognizer: it reports partial results while the user is still speaking, and it can be restricted to a fixed phrase list, which raises the hit rate for voice commands dramatically.
| Source | |
|---|---|
| Project | https://alphacephei.com/vosk/ |
| Libraries (releases) | https://github.com/alphacep/vosk-api/releases |
| Models | https://alphacephei.com/vosk/models |
You need the shared library libvosk.dll (Windows), libvosk.so (Linux) or
libvosk.dylib (macOS), plus one model per language. A Vosk model is a
directory, not a file — vosk-model-small-de-0.15 for example. Unpack it and
point the engine at it:
LVosk.ModelDirectory := 'C:\tools\vosk'; // scanned for vosk-model-*
LVosk.ModelPath := 'vosk-model-small-de-0.15';
| Property | Default | Description |
|---|---|---|
LibraryPath |
— | Path of libvosk; empty searches next to the app and on the library path |
ModelPath |
— | Model directory to recognize with |
ModelDirectory |
— | Folder scanned for vosk-model-* directories |
MaxAlternatives |
0 | Number of alternative readings, 0 = best only |
LogLevel |
-1 | -1 silences the Vosk logging, 0 reports warnings and errors |
PartialWords |
False | Word timings in intermediate results as well |
Vosk is Apache-2.0 licensed; the models carry their own licenses.
Setting up the Component
uses
Gorilla.Audio.Manager, Gorilla.Audio.OpenAL,
Gorilla.Audio.STT, Gorilla.Audio.STT.Listener, Gorilla.Audio.STT.Whisper;
var LWhisper : TGorillaWhisperEngine;
begin
LWhisper := TGorillaWhisperEngine.Create(Self);
LWhisper.ModelDirectory := 'C:\tools\whisper\models';
LWhisper.ModelPath := 'base';
STT.AudioManager := GorillaOpenALManager1;
STT.Engine := LWhisper;
STT.Language := 'de';
STT.Mode := smPushToTalk;
STT.Active := true;
end;
AudioManager may be left empty — the component then uses the first manager
owned by the same form. Engine may be left empty too, in which case
EngineName ('Whisper', 'Vosk', or empty for the first registered backend)
decides which engine the component creates internally.
| Property | Default | Description |
|---|---|---|
Active |
False | Starts and stops recording |
Mode |
smContinuous |
How the component decides when to record |
Device |
— | Recording device out of GetDevices(); empty = system default |
SampleRate |
16000 | Leave it there — the recognizers work on 16 kHz |
Language |
— | e.g. de; empty asks the engine to detect it (whisper.cpp only) |
Prompt |
— | Context hint, e.g. the proper names of your game world |
Translate |
False | Lets the engine translate the result into English |
PartialResults |
False | Intermediate results while speaking (streaming engines only) |
UseGrammar |
False | Hands the command phrases to the engine as a grammar |
CommandThreshold |
0.75 | Similarity a phrase needs to fire its command |
AutoUpdate |
True | Drives Update() from an internal timer |
UpdateInterval |
16 | Interval of that timer in ms |
PollInterval |
20 | Interval the capture thread polls the device with |
MaxQueueLength |
8 | Utterances that may wait for the recognizer |
Listening Modes
| Mode | Behaviour |
|---|---|
smPushToTalk |
Records between BeginListen() and EndListen(); the release triggers the recognition. The most reliable mode in a noisy room |
smContinuous |
Records permanently, the detector cuts the stream into utterances |
smSingleShot |
Records until exactly one utterance was found, then stops |
// push to talk, e.g. from a key handler
procedure TForm1.FormKeyDown(...);
begin
if Key = vkT then STT.BeginListen();
end;
procedure TForm1.FormKeyUp(...);
begin
if Key = vkT then STT.EndListen();
end;
// "say the name of your character now"
STT.Listen(); // switches to smSingleShot and activates
STT.Stop(); // stop and discard everything not recognized yet
In smPushToTalk everything between the two calls is one utterance and the
voice activity detector is bypassed. In the other modes BeginListen() only
switches recording on — the detector then decides where an utterance starts and
ends, so EndListen() has nothing to trigger.
Voice Commands
For a game the raw text is rarely the goal. A command bundles the synonyms a player might use under one name the application reacts to:
var LCmd : TGorillaSTTCommand;
begin
LCmd := STT.Commands.Add('Attack', ['angriff', 'attackieren', 'greif an']);
LCmd.Threshold := 0.8; // stricter than the component default
STT.Commands.Add('Follow', ['folge mir', 'komm mit']);
STT.UseGrammar := true; // Vosk: restrict the recognizer to these phrases
end;
procedure TForm1.STTCommand(ASender : TObject;
const ACommand : TGorillaSTTCommand; const AConfidence : Single;
const AResult : TGorillaSTTResult);
begin
if ACommand.Name = 'Attack' then
Guard.Attack();
end;
| Member | Description |
|---|---|
Name |
The name reported by OnCommand |
Phrases |
The phrases that trigger it, one per line |
Enabled |
A disabled command is never matched |
Threshold |
Similarity needed; 0 uses the component's CommandThreshold |
Tag |
Free for application use |
Match(AText) |
Best similarity of any phrase, 1.0 for a literal hit |
UseGrammar hands all phrases of all enabled commands to the engine. With a
grammar capable engine (Vosk) that raises the hit rate dramatically, at the
price of no longer understanding anything else — perfect for a command-only
mode, wrong for a chat window. Engines without grammar support (whisper.cpp) get
the phrases as a context prompt instead.
Matching can also be done manually, e.g. for text that came from somewhere else:
if STT.MatchCommand('greif an', LCmd, LConfidence) then ...;
Results
procedure TForm1.STTResult(ASender : TObject; const AResult : TGorillaSTTResult);
var LWord : TGorillaSTTWord;
begin
Memo1.Lines.Add(AResult.Text);
for LWord in AResult.Words do
Memo1.Lines.Add(Format(' %s %.2f - %.2f (%.0f%%)',
[LWord.Text, LWord.StartTime, LWord.EndTime, LWord.Confidence * 100]));
end;
| Member | Description |
|---|---|
Text |
The recognized sentence |
Words |
Word timings, empty when the backend does not report them |
Alternatives |
Alternative readings, empty when none were requested |
Language |
The language the engine detected or was told to use |
Confidence |
Overall confidence, 0..1 |
IsPartial |
True for an intermediate result; always followed by a final one |
EngineName |
Which backend produced it |
Duration, StartTime |
Length and position of the utterance in seconds |
WordCount, IsEmpty |
Convenience |
The result is owned by the component and invalid after the handler returned — copy what you need.
Voice Activity Detection
The detector decides where an utterance begins and ends. The built-in one is
energy based and adapts to the noise floor; it registers itself under the name
Energy, and VADName picks a different one if you registered your own.
| Property | Default | Description |
|---|---|---|
Threshold |
0.012 | Absolute level a frame has to exceed |
NoiseMultiplier |
2.5 | Factor applied to the tracked noise floor |
MinSpeechDuration |
0.25 s | Shorter utterances are discarded as a click or a cough |
MinSilenceDuration |
0.6 s | Pause that ends an utterance |
PreRollDuration |
0.3 s | Audio kept in front of the detected speech, so the plosive of the first word survives |
MaxSegmentDuration |
15 s | Emergency brake for a speaker who never pauses |
MaxZeroCrossingRate |
0.42 | Above this, a loud frame is treated as noise |
NoiseAdaption |
0.05 | How quickly the noise floor follows the input |
The effective threshold is the larger of Threshold and
NoiseFloor * NoiseMultiplier, which is what lets the detector work in a room
with a fan running. Reach the instance through ActiveVAD() while the component
is active.
MinSilenceDuration is the tuning knob that matters most: too short cuts
sentences apart at every breath, too long adds latency to every result.
Capture Devices
Recording goes through the audio driver already in your scene:
| Backend | Name |
|---|---|
| OpenAL capture | OpenAL |
| FMOD record | FMOD |
| Null device | None |
ComboBox1.Items.AddStrings(STT.GetDevices());
STT.Device := ComboBox1.Text;
ActiveCapture() returns the backend in use while active. It reports health
data worth logging during development — captured frames, startup latency, and
the share of real time the device actually delivers. A driver that silently
drops samples is the most confusing failure of the whole subsystem: recording
"works", the level meter moves, and the recognizer returns nonsense because it
is fed audio with holes in it.
Testing without a Microphone
// synchronous, does not touch the capture layer at all
LResult := STT.RecognizeFile('test\utterance.wav');
try
Memo1.Lines.Add(LResult.Text);
STT.DispatchResult(LResult); // run it through the voice command matching too
finally
LResult.Free();
end;
SaveLastSegment() writes exactly what the recognizer was handed last into a
wave file — with smPushToTalk, BeginListen(), a few spoken words and
EndListen(), that is the fastest way to find out whether a recognition problem
is a capture problem.
Events
| Event | Fired when |
|---|---|
OnSpeechStart |
The detector found the start of speech |
OnSpeechEnd |
An utterance ended |
OnPartial |
Intermediate result of a streaming engine |
OnResult |
An utterance was recognized |
OnCommand |
The recognized text matched a command — fires after OnResult |
OnError |
Recording or recognition failed |
State for a UI: IsListening, IsSpeaking, Level (0..1, ready for a level
meter) and DroppedSegments. Anything above zero in DroppedSegments means
the engine is too slow for the mode — use a smaller model, or switch to
push-to-talk.
Events are queued by the worker threads and raised by Update(). AutoUpdate
does that on a timer; switch it off to call Update() from your render loop.
Platform Support
| Windows | Linux | macOS | Android/iOS | |
|---|---|---|---|---|
| Capture (OpenAL / FMOD) | Yes | Yes | Yes | Yes |
whisper.cpp wmLibrary |
Yes | Yes | Yes | Yes |
whisper.cpp wmProcess |
Yes | Yes | Yes | No (no process spawning) |
| Vosk | Yes | Yes | Yes | Yes |
On mobile platforms use the library mode. Also remember that recording needs a microphone permission in the app manifest.
Troubleshooting
| Symptom | Cause |
|---|---|
IsAvailable() false |
Library or model not found — check LibraryFile(), GetModels() |
| "whisper-cli could not be found" | Neither library nor executable resolved; set ExecutablePath |
| Level meter moves, text is nonsense | The device drops samples — check the capture health data, raise PollInterval sensitivity |
| Sentences are cut in half | MinSilenceDuration too short |
| Nothing is recognized in a quiet room | Threshold too high, or the wrong Device |
| Every cough is recognized | MinSpeechDuration too low |
DroppedSegments grows |
Engine too slow — smaller model, fewer threads elsewhere, or push-to-talk |
| No partial results | PartialResults only works with a streaming engine (Vosk) |
| Commands never fire | CommandThreshold too strict, or the phrases do not match the language of the model |
Best Practices
- Ship neither the engines nor the models — document the download for your users, or fetch it in your installer
- Push-to-talk beats continuous listening in any room with other people in it
- Start with
ggml-base.binand only go bigger when the text quality is actually the problem - Set
Temperature := 0for voice commands - Fill
Promptwith the proper names of your game world — it noticeably improves the spelling of unusual words - Copy what you need out of the result; it dies with the handler
- Watch
DroppedSegmentsduring development, log it in release builds - Ask for the microphone permission before switching
Activeon
See Also
API Reference
- Gorilla.Audio.STT — Request, result, engine base class
- Gorilla.Audio.STT.Listener — Component and voice commands
- Gorilla.Audio.STT.Whisper — whisper.cpp backend
- Gorilla.Audio.STT.Vosk — Vosk backend
- Gorilla.Audio.STT.VAD — Voice activity detection
- Gorilla.Audio.STT.Capture — Capture backends
Related Topics
- Audio Manager — The manager the capture backend comes from
- Text-to-Speech — The other direction
- Input Controller — Binding push-to-talk to a key or gamepad button
- Dialogue System — Reacting to recognized commands in a dialogue tree