API
Functions
Section titled “Functions”listen
Section titled “listen”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:
onInterim
Section titled “onInterim”(transcript: string) => void. Called while the user is speaking.
signal
Section titled “signal”AbortSignal. Aborts the session, which rejects with aborted.
useSpeechRecognition
Section titled “useSpeechRecognition”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 |
onResult
Section titled “onResult”({ transcript, alternatives }) => void. A phrase is final.
onError
Section titled “onError”(error: SpeechError) => void
(reason: 'completed' | 'aborted' | 'error') => void. Not called when start() fails.
useHoldToTalk
Section titled “useHoldToTalk”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:
onSend
Section titled “onSend”(transcript: string) => void. Released: this is what was said. Never empty.
onCancel
Section titled “onCancel”(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 |
cancelDirection
Section titled “cancelDirection”'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.
useSpeechVolume
Section titled “useSpeechVolume”const level = useSpeechVolume(); // 0 … 1Renders 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
Section titled “addListener”addListener(name, listener): { remove(): void }. Listens to the events of all sessions.
getCapabilities
Section titled “getCapabilities”getCapabilities(locale?). Returns recognition, onDevice, contextualStrings and punctuation: what can work here.
getSupportedLocalesAsync
Section titled “getSupportedLocalesAsync”Locales the recognizer reports. Empty when the platform cannot tell.
useSpeechPermissions
Section titled “useSpeechPermissions”Permission hook, next to getPermissionsAsync() and requestPermissionsAsync(). start() and listen() already ask: use it to ask earlier, or to explain why.
Options
locale
Section titled “locale”string. BCP-47 tag such as vi-VN. Defaults to the device locale.
continuous
Section titled “continuous”boolean, default false. Keep listening after each phrase, until stop() or abort().
interimResults
Section titled “interimResults”boolean, default true. Emit results while the user is still speaking.
maxAlternatives
Section titled “maxAlternatives”number, default 1. Upper bound for alternatives.
silenceTimeout
Section titled “silenceTimeout”number, default 2000. Longest pause inside a phrase, in milliseconds. Recognizers may end it sooner.
contextualStrings
Section titled “contextualStrings”string[]. Words to favor, such as names and product terms. iOS, Android 13+.
punctuation
Section titled “punctuation”boolean, default true. Add punctuation. iOS, Android 13+.
requiresOnDeviceRecognition
Section titled “requiresOnDeviceRecognition”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
startemits exactly oneend.errorcomes 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.
SpeechError
Section titled “SpeechError”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 |