createSTT()
Creates an offline speech-to-text engine instance for transcribing complete audio files or buffers. Call destroy() when done to free native resources.
function createSTT(
options: STTInitializeOptions | ModelPathConfig
): Promise<SttEngine>
Parameters
options
STTInitializeOptions | ModelPathConfig
required
Configuration object or simple model path. See Configuration for full options.
Returns
Promise resolving to an SttEngine instance.
Example
const stt = await createSTT({
modelPath: { type: 'asset', path: 'models/whisper-tiny' },
modelType: 'whisper',
modelOptions: {
whisper: {
language: 'en',
task: 'transcribe'
}
}
});
const result = await stt.transcribeFile('/path/to/audio.wav');
console.log(result.text);
await stt.destroy();
SttEngine
Offline STT engine interface returned by createSTT().
Properties
Unique identifier for this engine instance.
Methods
transcribeFile()
Transcribe audio from a file path.
transcribeFile(filePath: string): Promise<SttRecognitionResult>
Absolute path to audio file (WAV, FLAC, etc.).
Returns: Promise resolving to SttRecognitionResult.
Example:
const result = await stt.transcribeFile('/sdcard/recording.wav');
console.log('Text:', result.text);
console.log('Tokens:', result.tokens);
console.log('Language:', result.lang);
transcribeSamples()
Transcribe audio from PCM samples in memory.
transcribeSamples(
samples: number[],
sampleRate: number
): Promise<SttRecognitionResult>
PCM audio samples as float values in range [-1, 1].
Sample rate in Hz (e.g. 16000, 44100).
Returns: Promise resolving to SttRecognitionResult.
Example:
const samples = new Float32Array(audioBuffer);
const result = await stt.transcribeSamples(
Array.from(samples),
16000
);
console.log(result.text);
setConfig()
Update runtime configuration (hotwords, decoding method, etc.) without recreating the engine.
setConfig(config: SttRuntimeConfig): Promise<void>
Example:
await stt.setConfig({
decodingMethod: 'modified_beam_search',
maxActivePaths: 8,
hotwordsFile: '/path/to/hotwords.txt',
hotwordsScore: 2.0
});
destroy()
Release native resources. The engine cannot be used after calling this method.
Example:
detectSttModel()
Detect STT model type and structure without initializing the recognizer. Stateless utility function.
function detectSttModel(
modelPath: ModelPathConfig,
options?: { preferInt8?: boolean; modelType?: STTModelType }
): Promise<{
success: boolean;
detectedModels: Array<{ type: string; modelDir: string }>;
modelType?: string;
}>
Parameters
Model path configuration (asset, file, or auto).
Optional detection options.
Prefer int8 quantized models.
Force specific model type detection.
Returns
Object with detection results:
success: Whether detection succeeded
detectedModels: Array of detected model types and directories
modelType: Primary detected model type
Example
const result = await detectSttModel({
type: 'asset',
path: 'models/sherpa-onnx-whisper-tiny-en'
});
if (result.success && result.detectedModels.length > 0) {
console.log('Detected:', result.modelType);
console.log('Models:', result.detectedModels);
}