Gorilla.Audio.STT.Vosk Unit Reference

Overview

The Gorilla.Audio.STT.Vosk unit implements TGorillaVoskEngine, a local streaming speech recognition backend driving Vosk. Unlike whisper.cpp it reports intermediate results while the user is still speaking, and it can be restricted to a phrase list, which raises the hit rate for voice commands dramatically.

The engine registers itself in the initialization section of the unit, so adding the unit makes 'Vosk' selectable through EngineName.

The Vosk library and its models are not part of the Gorilla3D distribution. See Getting Vosk.

Class Hierarchy

TGorillaSTTEngine
  └── TGorillaVoskEngine

TGorillaVoskEngine

Class Methods

Method Description
GetEngineName() Returns 'Vosk'
IsSupported() False when the platform cannot load the library

Capability Queries

Method Result
IsAvailable() True when library and model were resolved
IsThreadSafe() Reports whether parallel recognition is allowed
SupportsStreaming() True — partial results while speaking
SupportsGrammar() True — can be restricted to a phrase list

Public Methods

Method Description
LibraryAvailable() True when the Vosk shared library could be loaded
LibraryFile() Path of the library in use, empty when none
GetModels() Model directories found in ModelDirectory
Unload() Frees model and recognizer; the next call reloads them

Published Properties

Property Type Default Description
LibraryPath String — Path of the Vosk shared library; empty searches next to the application and on the system library path
ModelPath String — Model directory used for recognition: absolute path or a directory name inside ModelDirectory
ModelDirectory String — Folder scanned for vosk-model-* directories
MaxAlternatives Integer 0 Alternative readings the recognizer reports; 0 asks for the best one only
LogLevel Integer -1 Verbosity of the Vosk internal logging; -1 silences it, 0 reports warnings and errors
PartialWords Boolean False Word timings in the intermediate results as well, at a little performance cost
Grammar fallback String [unk] Token added to every grammar so the recognizer has a way to report something outside it

Inherited from TGorillaSTTEngine: DefaultLanguage, WordTimings.

Protected Methods (for implementers)

Method Description
ResolveModel(AName, ...) Resolves a model identifier into an absolute directory path
EnsureModel(AModel) Loads the model, reusing an already loaded one
EnsureRecognizer(ASampleRate) Creates the recognizer, recreating it when the grammar changed
ReleaseRecognizer() / ReleaseModel() Release the corresponding handles
BuildGrammarJson(APhrases) Builds the JSON phrase list Vosk expects as a grammar
ParseJsonResult(AJson, AResult) Reads a Vosk JSON result
ParseJsonPartial(AJson, AResult) Reads a Vosk JSON partial result
DoRecognize / DoFeed / DoFlush / DoResetStream / DoGrammarChanged The streaming implementation

Library Names

Platform Library
Windows libvosk.dll
macOS libvosk.dylib
Linux libvosk.so

Constants

Constant Value Description
GORILLA_VOSK_MODEL_PREFIX vosk-model Prefix of the model directory names
GORILLA_VOSK_UNKNOWN [unk] Token representing anything outside the grammar

Remarks

A Vosk model is a directory, not a file — vosk-model-small-de-0.15 for example. There is one model per language; Vosk cannot detect the language on its own, which is the main difference to whisper.cpp in practice.

Enabling UseGrammar on the listener component restricts the recognizer to the phrases of all enabled voice commands. That makes command recognition much more reliable, but nothing outside the list is understood any more — the recognizer then reports [unk].

See Also