Skip to content

API

listen(options?: ListenOptions): Promise<{ transcript: string; alternatives: string[] }>

Listens to one phrase. Resolves when the user stops talking, or with an empty transcript when stop() is called before anything was said. Rejects with a SpeechError. Takes the options below, except continuous and interimResults, and:

(transcript: string) => void. Called while the user is speaking.

AbortSignal. Aborts the session, which rejects with aborted.

const speech = useSpeechRecognition(options?);

Drives a session from a component. Ignores sessions started elsewhere, and aborts its own when the component unmounts. Takes the options below and three callbacks.

Returns
status idle, starting, listening, stopping
isActive The status is not idle
transcript Final and interim text: what to show
finalTranscript Will not change anymore
interimTranscript The phrase being spoken
error SpeechError | null
start(options?) Clears the transcript and starts. Resolves to whether it is listening, never rejects
stop() Keeps what was said
abort() Drops the phrase being spoken
toggle() Starts or stops
reset() Clears the transcript and the error

({ transcript, alternatives }) => void. A phrase is final.

(error: SpeechError) => void

(reason: 'completed' | 'aborted' | 'error') => void. Not called when start() fails.

const talk = useHoldToTalk({ onSend: (transcript) => send(transcript) });
<View {...talk.holdProps}>
<Text>{talk.isCancelling ? '🗑' : talk.isHolding ? '…' : '🎙'}</Text>
</View>

Hold a button to talk, release it to send, slide away to cancel. Brings the gesture and the session, not the looks. Takes the options below, except continuous, and:

(transcript: string) => void. Released: this is what was said. Never empty.

(reason) => void. Released, and there is nothing to send. Not called after an error: see onError.

reason
cancelled Slid away, or the system took the gesture
too-short Released before minDuration
not-ready Released before the microphone was open, for instance to answer the permission dialog
empty Nothing was said

'left' | 'right' | 'up' | 'none', default 'left'. Which way to slide to cancel.

Option Default
cancelDistance 90 How far to slide to cancel
minDuration 300 Shorter presses are accidents, in milliseconds
maxDuration 60000 Sends by itself after this time
releaseDelay 250 Keeps listening this long after the release, for the last word
disabled false Ignores the button, and releases it if it is held

Returns holdProps, isHolding, isCancelling and cancel(), and from useSpeechRecognition: status, isActive, transcript, finalTranscript, interimTranscript and error.

const level = useSpeechVolume(); // 0 … 1

Renders about 15 times per second while listening: use it in a small component of its own.

start(options?): Promise<void>. Asks for permission when needed and resolves once the microphone is open. Rejects with a SpeechError.

Stops listening and delivers the final result. Does nothing without a session.

Stops listening and drops the result. Does nothing without a session.

addListener(name, listener): { remove(): void }. Listens to the events of all sessions.

getCapabilities(locale?). Returns recognition, onDevice, contextualStrings and punctuation: what can work here.

Locales the recognizer reports. Empty when the platform cannot tell.

Permission hook, next to getPermissionsAsync() and requestPermissionsAsync(). start() and listen() already ask: use it to ask earlier, or to explain why.

Options

string. BCP-47 tag such as vi-VN. Defaults to the device locale.

boolean, default false. Keep listening after each phrase, until stop() or abort().

boolean, default true. Emit results while the user is still speaking.

number, default 1. Upper bound for alternatives.

number, default 2000. Longest pause inside a phrase, in milliseconds. Recognizers may end it sooner.

string[]. Words to favor, such as names and product terms. iOS, Android 13+.

boolean, default true. Add punctuation. iOS, Android 13+.

boolean, default false. Never send audio to a server. Rejects when that is impossible.

Events

Event Payload
start
result { transcript, alternatives, isFinal, segment }
volume { level }
error { code, message }
end { reason }
  • A session that emits start emits exactly one end. error comes right before it.
  • A session that fails earlier emits nothing: the promise rejects.
  • Going to the background ends the session on iOS and Android, with interrupted.
  • There is one microphone, so one session at a time. A second one rejects with busy.

Has a code and a message. SpeechError.from(error) wraps whatever a catch receives.

code Meaning
not-allowed A permission is missing
language-not-supported The locale is unsupported, or its model is not installed
no-speech Nothing was recognized
network The recognizer needs a connection
audio-capture The microphone failed
busy Another session is running
interrupted A call, or the app went to the background
service-unavailable There is no usable recognizer
aborted You cancelled it
unknown Anything else