Skip to main content

Overview

The offline STT (Speech-to-Text) module provides complete audio file transcription using sherpa-onnx models. Use this when you have complete audio files to transcribe, as opposed to real-time streaming recognition. Key features:
  • Transcribe complete audio files or PCM samples
  • Support for multiple model types (Whisper, Paraformer, Transducer, and more)
  • Automatic model type detection
  • Hotwords support for contextual biasing (transducer models)
  • Token timestamps and language detection (model-dependent)
  • Runtime configuration updates

Quick Start

Supported Model Types

The following model types are supported with automatic detection:
Use modelType: 'auto' to automatically detect the model type based on files in the directory. This is the recommended approach.

API Reference

createSTT(options)

Creates an STT engine instance for offline transcription.
src/stt/index.ts
Options:
modelPath
ModelPathConfig
required
Model directory path configuration. Can be:
  • { type: 'asset', path: 'models/...' } for bundled assets
  • { type: 'file', path: '/absolute/path' } for filesystem
  • { type: 'auto', path: '...' } to try asset then file
modelType
STTModelType
default:"auto"
Model type to use. Set to 'auto' for automatic detection based on files.
preferInt8
boolean
Prefer int8 quantized models (faster, smaller) when available.
  • true: Prefer int8 models
  • false: Prefer full precision
  • undefined: Try int8 first, fallback to full precision (default)
numThreads
number
default:"1"
Number of threads for inference.
provider
string
default:"cpu"
Execution provider (e.g., 'cpu', 'qnn', 'nnapi', 'xnnpack'). See Execution Providers for details.
hotwordsFile
string
Path to hotwords file for contextual biasing. Only supported for transducer models (transducer, nemo_transducer).
hotwordsScore
number
default:"1.5"
Hotwords boost score (only applies when hotwordsFile is set).
debug
boolean
default:"false"
Enable debug logging in native layer.
modelOptions
SttModelOptions
Model-specific options. Only the block for the loaded model type is applied:
  • whisper: { language, task, tailPaddings, enableTokenTimestamps, enableSegmentTimestamps }
  • senseVoice: { language, useItn }
  • canary: { srcLang, tgtLang, usePnc }
  • funasrNano: { systemPrompt, userPrompt, maxNewTokens, temperature, topP, seed, language, itn, hotwords }

SttEngine: transcribeFile(filePath)

Transcribe a complete audio file.
Input requirements:
  • Format: WAV (PCM)
  • Sample rate: 16 kHz (recommended, model-dependent)
  • Channels: Mono
  • Bit depth: 16-bit
Returns SttRecognitionResult:
Audio format is critical. Most models expect 16 kHz mono WAV. Use ffmpeg to convert:

SttEngine: transcribeSamples(samples, sampleRate)

Transcribe from raw PCM samples (e.g., from microphone or decoder).
Parameters:
  • samples: Float PCM samples in range [-1, 1], mono
  • sampleRate: Sample rate in Hz

SttEngine: setConfig(config)

Update recognizer configuration at runtime.

SttEngine: destroy()

Release native resources. Must be called when the engine is no longer needed.

Model-Specific Options

Whisper Models

Language codes must be valid. Invalid language codes can crash the app. Use getWhisperLanguages() to get the list of supported languages:

SenseVoice Models

Canary Models

Hotwords (Contextual Biasing)

Hotwords allow you to boost recognition of specific words or phrases.
Hotwords are only supported for transducer models (transducer, nemo_transducer). Check support before showing UI:

Hotwords File Format

Create a text file with one phrase per line, optionally with a boost factor:

Using Hotwords

Model Detection

Detect model type without initializing:

Performance Optimization

Quantization

Int8 quantized models are faster and use less memory:

Threading

Increase threads for faster processing on multi-core devices:

Hardware Acceleration

Use hardware acceleration when available:
See Execution Providers for detailed information on hardware acceleration.

Common Use Cases

Transcribe with Language Detection

Batch Processing Multiple Files

Troubleshooting

  • Verify the model directory exists and contains all required files
  • Check that model files match the expected structure for the model type
  • Try modelType: 'auto' to let the SDK detect the type
  • Enable debug: true to see detailed initialization logs
  • Ensure audio is 16 kHz mono WAV (most models)
  • Check audio quality and noise levels
  • Try a larger/better model
  • Use preferInt8: false for full precision
  • Verify the model type supports hotwords (transducer, nemo_transducer only)
  • Check modelingUnit and bpeVocab are set correctly for BPE models
  • Ensure hotwords file format is correct (one phrase per line)
  • Increase hotwordsScore for stronger boosting
  • Use preferInt8: true for smaller models
  • Reduce numThreads
  • Process shorter audio segments
  • Close other apps to free memory

Next Steps

Streaming STT

Real-time recognition with partial results

Model Setup

Learn how to bundle and load models

Execution Providers

Hardware acceleration (QNN, NNAPI, XNNPACK)

Text-to-Speech

Convert text to speech