fn

useSpeechRecognition

v0.0.14testeddemo

Reactive wrapper around the Web Speech API SpeechRecognition for transcribing speech to text.

Examples

ts
const { isSupported, isListening, result, start, stop } = useSpeechRecognition({ lang: 'en-US' });
start();
ts
// Toggle from a button, read the live transcript
const { result, isFinal, toggle } = useSpeechRecognition({ continuous: true });
watch(result, transcript => console.log(transcript));

Demo

Loading demo…

Signature

ts
export function useSpeechRecognition(options: UseSpeechRecognitionOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseSpeechRecognitionOptionsConfiguration options

Returns

UseSpeechRecognitionReturnSupport flag, reactive listening/result/error state, and start/stop/toggle controls
PropertyTypeDescription
isSupportedComputedRef<boolean>Whether the SpeechRecognition API is supported in the current environment.
isListeningShallowRef<boolean>Whether recognition is currently active. Writable: setting it starts/stops the recognizer, mirroring start() / stop().
isFinalReadonly<ShallowRef<boolean>>Whether the latest result is final (true) or interim (false).
resultReadonly<ShallowRef<string>>Transcript of the most recent recognition result.
confidenceReadonly<ShallowRef<number>>Confidence (0-1) the engine has in the most recent result.
errorShallowRef<SpeechRecognitionErrorEvent | Error | undefined>The most recent error, or undefined when none.
recognitionSpeechRecognition | undefinedThe underlying SpeechRecognition instance, or undefined when unsupported.
start() => voidStart listening.
stop() => voidStop listening.
toggle(value?: boolean) => voidToggle listening. Pass a boolean to force a state.