Skip to main content

Overview

Hotwords (also called contextual biasing or keyword spotting) allow you to boost recognition accuracy for specific words or phrases. This is particularly useful for domain-specific vocabulary, proper nouns, technical terms, or commands that the base model might not recognize well.
Hotwords are only supported by transducer and nemo_transducer model types. All other model types (Whisper, Paraformer, Sense Voice, etc.) do not support hotwords.
Import from: react-native-sherpa-onnx/stt

Model Support

Only specific STT model types support hotwords:

Supported Models

  • transducer
  • nemo_transducer

Unsupported Models

  • whisper
  • paraformer
  • sensevoice
  • nemo_ctc
  • All other types

Checking Model Support

Use sttSupportsHotwords() to check if a model type supports hotwords:
boolean
Returns true only for 'transducer' and 'nemo_transducer'

Error Codes

The SDK validates hotword configuration and rejects with specific error codes:

Hotword File Format

Hotword files must follow this format:
1

UTF-8 text file

The file must be valid UTF-8 text with no null bytes
2

One word/phrase per line

Each non-empty line contains a single word or phrase to boost
3

Optional score per line

Add a space, colon, and numeric score to adjust boost strength
Higher scores = stronger boosting (default: 1.0 if not specified)
4

Must contain letter characters

Each line must have at least one letter character. Lines with only digits, punctuation, or symbols are rejected.

Example Hotwords File

hotwords.txt

Configuration

Initialize with Hotwords

Provide the hotwords file path during STT initialization:
string
Path to the hotwords text file (must be readable and valid)
number
Global score multiplier applied to all hotwords (default: 1.5)

Update Hotwords at Runtime

You can change hotwords dynamically using setConfig():
You can create multiple hotword files for different contexts (e.g., one for technical terms, one for commands) and switch between them at runtime.

Automatic Decoding Method Switch

When you provide a non-empty hotwords file, the SDK automatically switches to modified_beam_search decoding method, because sherpa-onnx only applies hotwords with this method.
You don’t need to manually set decodingMethod: 'modified_beam_search'. The SDK handles this automatically.
The SDK also ensures maxActivePaths is at least 4 for proper beam search operation:

Modeling Unit and BPE Vocab

For proper hotword tokenization, you may need to specify the modeling unit and (optionally) the BPE vocabulary file.
These parameters are only relevant when using hotwords. They tell the tokenizer how to process hotword text to match the model’s training.

modelingUnit

The modeling unit must match how your model was trained:
'cjkchar' | 'bpe' | 'cjkchar+bpe'
Tokenization method for hotwords

bpeVocab

string
Path to the BPE vocabulary file (sentencepiece bpe.vocab)
Only needed when:
  • modelingUnit is 'bpe' or 'cjkchar+bpe'
  • The model directory doesn’t contain an auto-detectable bpe.vocab file
If the model directory contains bpe.vocab, it’s detected automatically and used when bpeVocab is not provided.

Configuration Examples

English Transducer with BPE

Hotwords file:

Chinese Transducer (Character-based)

Hotwords file:

Bilingual Transducer (Chinese + English)

Hotwords file:

Use Cases

Technical Terms

Boost recognition of domain-specific jargon, API names, or technical vocabulary that the base model might misrecognize.

Proper Nouns

Improve accuracy for company names, product names, or person names.

Voice Commands

Enhance command recognition for voice control interfaces.

Medical Terms

Boost medical vocabulary for healthcare applications.

Best Practices

Always use sttSupportsHotwords() to verify model support before showing hotwords configuration UI.
  • Default (1.0): Good starting point for most words
  • High (1.5-2.5): Use for critical commands or frequently misrecognized terms
  • Very high (2.5+): May cause over-recognition or false positives
Start conservative and adjust based on testing.
Always set modelingUnit to match how your model was trained:
  • Check model documentation or README
  • Look for bpe.vocab or bpe.model files in the model directory
  • If unsure, 'bpe' is most common for English models
Large hotword files can impact performance. Aim for:
  • 50-200 entries: Optimal range for most use cases
  • 500+ entries: May slow down recognition
  • Consider creating context-specific files instead of one giant file
Ensure hotwords files:
  • Are valid UTF-8
  • Have at least one letter per line
  • Use correct score syntax ( :1.5)
  • Don’t contain SRT timestamps or numeric-only lines
Create multiple hotword files for different contexts and switch between them:

Troubleshooting

Cause: You’re using a model type that doesn’t support hotwords (e.g., Whisper, Paraformer).Solution:
  • Use a transducer or nemo_transducer model instead
  • Remove the hotwordsFile parameter if you must use an unsupported model
  • Check model type with sttSupportsHotwords(modelType) before enabling hotwords
Cause: The hotwords file has formatting issues.Solution:
  • Ensure file exists and is readable
  • Check for invalid UTF-8 or null bytes
  • Verify each line has at least one letter character
  • Check score syntax: must be :1.5 (space, colon, number)
  • Remove SRT timestamps or numeric-only lines
Possible causes:
  • Score too low (increase to 1.5-2.0)
  • Wrong modelingUnit for your model
  • Missing or incorrect bpeVocab path
  • Hotword phrase doesn’t match audio pronunciation
Solutions:
  • Increase hotword scores gradually
  • Verify modelingUnit matches model training
  • Check for bpe.vocab in model directory
  • Test with simpler single-word hotwords first
Cause: Hotword scores are too high.Solution:
  • Reduce scores to 1.0-1.5 range
  • Remove overly generic terms
  • Use more specific multi-word phrases instead of single words

readonly string[]
Constant array containing all model types that support hotwords