Skip to main content
transcribe() converts a buffer of PCM audio to text using an on-device speech recognition model.

Basic usage

Setup

Register the ONNX module at launch, then load an STT model through the unified lifecycle. There is no loadSTTModel; every modality goes through loadModel(_ request:) with a category.
loadModel does not throw. Check success on the returned RAModelLoadResult.

Method signature

audioData holds raw PCM samples. The call throws SDKException with code .notInitialized when no model is loaded under .speechRecognition. For chunked input, use transcribeStream.

Audio requirements

RASTTOutput

RASTTOutput also exposes detectedLanguageCode, a Swift convenience that returns the language enum value.

Examples

Record and transcribe

Word timestamps

Timestamps are in milliseconds (startMs, endMs), not seconds.

Language selection

RASTTOptions.language is the RASTTLanguage enum, not a string. .defaults() sets .en.

SwiftUI voice input

Model management

The lifecycle API is shared across every modality.

Registering a Whisper model

Sherpa-ONNX Whisper models ship as tar.gz archives, so use the archive overload of registerModel.

Error handling

Streaming STT

Real-time transcription

STT Options

Configure transcription