Skip to content

API: ai/nlu-voice-wasm

@mosaicoo/svg-engine/ai/nlu-voice-wasm provides 100% local, offline speech-to-text via Whisper (transformers.js + onnxruntime-web WASM). It’s a heavy, opt-in entry point — the ML dependencies load lazily, only when voice is actually used. No Angular Material/CDK dependency.

import { provideWhisperVoiceEngine } from '@mosaicoo/svg-engine/ai/nlu-voice-wasm';

Register the engine in your app providers; VoiceEngineService (from ai/nlu-ui) then discovers it as the whisper engine.

APIDescription
provideWhisperVoiceEngine(config?)The complete bootstrap: registers the config and WhisperVoiceService as the VOICE_WHISPER_PROVIDER. Put it in your root providers[].
provideWhisperVoice(config?)Registers just the config (merged with the defaults).
WhisperVoiceServiceThe provider itself — same VoiceProvider contract as the Web Speech one, but transcribing on-device: listen(lang?, options?) records (with voice-activity detection) and transcribes locally; isSupported/listening/modelLoading/lastError signals. Multilingual (PT-BR / ES / EN).
WHISPER_VOICE_CONFIG / DEFAULT_WHISPER_VOICE_CONFIGThe config injection token and its defaults.

WhisperVoiceConfig controls the model, the WASM runtime and the voice-activity-detection behaviour:

FieldDefaultMeaning
modelBasePath/assets/ml/whisperWhere transformers.js loads the model from.
modelIdwhisper-smallModel folder (e.g. whisper-base, whisper-small).
wasmBasePath/assets/ml/ort/Where the onnxruntime .wasm binaries are served.
dtypeq8Model quantization (q8/fp32/fp16/…).
numThreads1WASM threads (1 avoids the COOP/COEP requirement).
defaultLanguageptBCP-47 language used when the caller omits one.
maxRecordMs15000Max capture length before auto-stop.
silenceMs / silenceThreshold1000 / 0.015Voice-activity detection: silence duration and RMS energy threshold to auto-stop after speech.
noSpeechTimeoutMs6000Give up if no speech is detected.