Gorilla.Audio.STT.Whisper Unit Reference

Overview

The Gorilla.Audio.STT.Whisper unit implements TGorillaWhisperEngine, a local speech recognition backend driving whisper.cpp. It can either load the whisper.cpp shared library or call the whisper-cli executable and read the JSON it produced. The engine registers itself in the initialization section of the unit, so adding the unit makes 'Whisper' selectable through EngineName.

whisper.cpp and its models are not part of the Gorilla3D distribution. See Getting whisper.cpp.

Class Hierarchy

TGorillaSTTEngine
  └── TGorillaWhisperEngine

Enumerations

TGorillaWhisperMode

Value Description
wmAuto Use the shared library when it can be loaded, otherwise fall back to the command line tool
wmLibrary Only use the shared library, fail when it is missing
wmProcess Only use the command line tool

TGorillaWhisperEngine

Class Methods

Method Description
GetEngineName() Returns 'Whisper'
IsSupported() False where the resolved mode cannot work, e.g. wmProcess on mobile

Public Methods

Method Description
IsAvailable() True when library or executable and a model were resolved
IsThreadSafe() Reports whether parallel recognition is allowed
GetLanguages() Language codes whisper.cpp is able to recognize
ActiveMode() The mode the engine will actually work in, with wmAuto resolved
LibraryAvailable() True when the shared library could be loaded and its parameter layout matches the one this unit was written against
LibraryFile() Path of the shared library in use, empty when none
ResolveExecutable() The executable the engine will call in wmProcess, resolved against the system search path and the release layouts next to the application. Empty when whisper-cli could not be found
RefreshModels() Rescans ModelDirectory for ggml-*.bin files
GetModels() Model files found in ModelDirectory
Unload() Frees the loaded model; the next recognition loads it again

Published Properties

Property Type Default Description
Mode TGorillaWhisperMode wmAuto How the engine reaches whisper.cpp
LibraryPath String — Path of the shared library; empty searches next to the application and on the system library path
ExecutablePath String — Path of the whisper-cli executable; a bare name is searched on the system path
ModelPath String — Model used for recognition: absolute path, file name inside ModelDirectory, or a bare size name such as base or small.en
ModelDirectory String — Folder scanned for ggml-*.bin model files
CommandTemplate String see below Command line for wmProcess
Threads Integer 0 Threads the inference may use; 0 picks half of the available cores, which leaves room for the render loop
Timeout Integer 60000 Milliseconds a single recognition may take
UseGPU Boolean False Runs the inference on the GPU when the library was built with a GPU backend
MaxSegmentLength Integer 0 Maximum characters per segment, 0 for no limit — useful for subtitles
SplitOnWord Boolean True Keeps words intact when MaxSegmentLength splits a segment
Temperature Single — Sampling temperature; 0 is deterministic and the right choice for voice commands
NoSpeechThreshold Single — Probability above which a segment is discarded as silence, 0..1

Inherited from TGorillaSTTEngine: DefaultLanguage, WordTimings.

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.

Protected Methods (for implementers)

Method Description
ResolveModel(AVoiceId, out AModel) Resolves a model identifier into an absolute file path; accepts an absolute path, a file name inside ModelDirectory, or a bare size name such as base, which is expanded into ggml-base.bin
EnsureContext(AModel) Loads the model into the library, reusing an already loaded one
ReleaseContext() Releases the loaded model
DoRecognizeLibrary(...) Recognition through the shared library
DoRecognizeProcess(...) Recognition through whisper-cli
ParseJsonResult(AJson, AResult) Reads the JSON whisper-cli wrote into a result instance

Global Functions and Variables

Name Description
GorillaWhisperLibAvailable() True when the shared library could be loaded and initialized
GorillaWhisperLibFile() Path of the shared library in use, empty when none was found
GorillaWhisperLibraryPath Full path of the library all engine instances should use; leave empty to search next to the application and on the system library path. Has to be set before the first recognition

Library and Executable Names

Platform Library Executable candidates
Windows whisper.dll whisper-cli, main, whisper
macOS libwhisper.dylib same
Linux libwhisper.so, libwhisper.so.1 same

Constants

GORILLA_WHISPER_COMMAND

Default command line of the whisper-cli executable:

%EXE% -m %MODEL% -f %INPUT% -of %OUTPUT% -oj%JSONFULL%
      -t %THREADS% -np -l %LANGUAGE%%TRANSLATE%%PROMPT%

Placeholders: %EXE%, %MODEL%, %INPUT%, %OUTPUT%, %LANGUAGE%, %THREADS%, %TRANSLATE%, %PROMPT%, %JSONFULL%.

Other Constants

Constant Value Description
GORILLA_WHISPER_MODEL_PREFIX ggml- File name prefix of the GGML models
GORILLA_WHISPER_MODEL_EXT .bin File name extension of the GGML models
GORILLA_WHISPER_TIME_UNIT 0.01 whisper.cpp reports segment and token timings in units of 10 ms

Remarks

whisper.cpp works on 30 second windows; longer utterances are split — see GORILLA_STT_MAX_UTTERANCE in Gorilla.Audio.STT.

The backend does not support grammars. When UseGrammar is enabled on the listener component, the command phrases are handed over as a context prompt instead.

See Also