Checking Hotword Support
UsesttSupportsHotwords(modelType) to check if a model type supports hotwords:
true only for 'transducer' and 'nemo_transducer'.
Error Codes
| Code | When |
|---|---|
HOTWORDS_NOT_SUPPORTED | createSTT is called with a non-empty hotwordsFile and the model type is not transducer or nemo_transducer |
INVALID_HOTWORDS_FILE | Hotwords file is missing, not readable, invalid UTF-8, contains null bytes, has no valid lines, or has invalid score format |
Automatic Decoding Method Switch
When you provide a non-empty hotwords file, the SDK automatically sets the decoding method tomodified_beam_search (and ensures maxActivePaths is at least 4), because sherpa-onnx only applies hotwords with that method.
You do not need to set
decodingMethod manually. The init result includes decodingMethod so you can confirm which method was applied.Hotword File Format
For transducer and nemo_transducer models:- One word or phrase per line
- UTF-8 text; no null bytes
- Optional score per line:
word_or_phrase :1.5(space, colon, then a single number) - Each non-empty line must contain at least one letter character (lines with only digits, punctuation, or symbols are rejected)
Example Hotword File
The SDK validates the file when you pass a path: it must exist, be readable, and satisfy the rules above. Invalid files cause rejection with
INVALID_HOTWORDS_FILE.Modeling Unit and BPE Vocab
Only relevant when using hotwords. PassmodelingUnit (and if needed bpeVocab) so hotwords are tokenized correctly.
Set when using hotwords:
'cjkchar' | 'bpe' | 'cjkchar+bpe'Must match the model’s training unit. See the table below.Only needed when
modelingUnit is 'bpe' or 'cjkchar+bpe'Path to the BPE vocabulary file (sentencepiece bpe.vocab). For 'cjkchar' you do not need bpeVocab.If the model directory contains
bpe.vocab, it is detected automatically and used when bpeVocab is not provided (for bpe / cjkchar+bpe).When to Use Which Modeling Unit
The value depends on how the model was trained, not on the app. You find it in the model’s documentation (e.g. k2-fsa releases, Hugging Face card).BPE
Use for: English (or similar) transducer modelsExamples: “zipformer-en”, “icefall … en”, LibriSpeech modelsFiles: Model often has bpe.model or bpe.vocab in the folderHotwords file: One word/phrase per line (e.g.
SPEECH RECOGNITION)CJKChar
Use for: Chinese character-based transducer modelsExamples: “conformer-zh”, “wenetspeech”, “multi-dataset zh” modelsFiles: No BPE; tokens are charactersHotwords file: Chinese words per line (e.g.
语音识别)CJKChar+BPE
Use for: Bilingual Chinese + English transducer modelsExamples: “bilingual-zh-en”, “streaming zipformer bilingual”Files: Model often has bpe.vocabHotwords file: Can mix Chinese and English (e.g.
礼拜二, FOREVER)Usage Example
Validation Rules
The SDK validates the hotwords file when you initialize STT:File must exist and be readable
File must exist and be readable
The path must point to an existing file that the app can read.
UTF-8 text with no null bytes
UTF-8 text with no null bytes
The file must be valid UTF-8 text without null bytes.
At least one valid line
At least one valid line
The file must contain at least one non-empty line with letter characters.
Valid score format
Valid score format
If a line includes a score (e.g.
word :1.5), the part after : must be a valid number.No digit-only or symbol-only lines
No digit-only or symbol-only lines
Each line must contain at least one letter character (lines with only digits, punctuation, or SRT timestamps are rejected).
See Also
STT API
Complete Speech-to-Text API reference
Supported Models
View all supported model types
Model Setup
Learn how to set up and manage models
Streaming STT
Real-time speech recognition