jamsch/expo-speech-recognition
Speech Recognition for React Native Expo projects
What is this?
expo-speech-recognition is a library that lets React Native apps (built with Expo) understand spoken words. It works on iOS, Android, and web by tapping into each platform's built-in speech recognition system:
- iOS:
SFSpeechRecognizer - Android:
SpeechRecognizer - Web: the standard Web Speech API
The main goal is code reuse — you write your speech-recognition logic once, and it works across all three platforms without rewriting it for each one.
How do you use it?
- Install it with npm (the README shows commands for different Expo SDK versions).
- Configure a plugin in your
app.jsonfile. This plugin automatically adds the required permissions to your Android and iOS apps (microphone access, speech recognition access, and Android package visibility for Google's speech service). - Create a development build — if you're new to Expo and haven't generated native
ios/andandroid/folders yet, you'll need to runnpx expo run:androidandnpx expo run:iosonce.
Core usage patterns
1. Hooks (easiest)
The library provides a React hook called useSpeechRecognitionEvent that lets you listen to events like:
start— recognition beganend— recognition stoppedresult— a word or phrase was recognized (you get the transcript)error— something went wrong
You start recognition with ExpoSpeechRecognitionModule.start({ lang: "en-US", interimResults: true, continuous: false }) and stop it with .stop().
2. Permissions
Before starting, you should request permissions using requestPermissionsAsync(). If the user denies, you'll get an error event with code not-allowed. You can also check current permission status with getPermissionsAsync().
3. Direct module API
For more control, you can use the module directly:
addListener("eventName", callback)— register event listenersstart(options)— begin recognition with many configurable optionsstop()— stop and get a final resultabort()— cancel immediately without processing
What can you configure when starting?
The start() method accepts a rich options object, including:
- Language (
lang) — e.g.,"en-US" - Interim results — show partial results as you speak
- Continuous mode — keep listening until you stop (vs. stopping after a pause)
- On-device recognition — don't send audio over the network (if supported)
- Punctuation — add commas and full stops automatically
- Contextual strings — custom words unique to your app (e.g., chess player names)
- Android-specific options — like silence length, offensive-word masking, and which recognition service to use
- iOS-specific options — like audio session category and voice-processing settings
- Recording options — save the audio to a file (useful for later transcription)
- Audio source — transcribe an existing audio file instead of live microphone input
- Volume change events — get notified when input volume changes
Events you can listen to
The library fires events similar to the Web Speech API:
| Event | What it means |
|---|---|
start |
Recognition started — tell the user to speak |
audiostart / audioend |
Audio capture began / ended (includes file URI if recording was persisted) |
speechstart / speechend |
Sound / speech detected / stopped |
result |
A word or phrase was recognized (includes transcript, confidence, segments) |
nomatch |
No significant recognition happened |
error |
An error occurred (includes error code and message) |
end |
Service disconnected — always the last event |
volumechange |
Input volume changed (value between -2 and 10; below 0 is inaudible) |
languagedetection |
Language detection results (Android 14+ only) |
Other notable features
- Persisting audio recordings — save the microphone input to a file (Android 13+ and iOS)
- Transcribing audio files — pass a local audio file URI to
audioSourceand get a transcript - Volume metering — enable
volumeChangeEventOptionsto get volume updates - Polyfilling the Web SpeechRecognition API — can act as a drop-in replacement for the web API
- Muting the beep sound on Android — suppress the default beep
- Improving accuracy of single-word prompts — options to help with short commands
- Language detection — Android 14+ with Google's assistant service
API methods (summary)
The README lists many methods, including:
start(),stop(),abort()— control recognitionrequestPermissionsAsync(),getPermissionsAsync()— permission handling (plus separate microphone and speech-recognizer variants)getStateAsync()— current recognition stategetSupportedLocales()— available languagesgetSpeechRecognitionServices(),getDefaultRecognitionService(),getAssistantService()— Android-only service discoveryisRecognitionAvailable(),supportsOnDeviceRecognition(),supportsRecording()— capability checksandroidTriggerOfflineModelDownload()— download offline models on Android- iOS audio session methods —
setCategoryIOS(),getAudioSessionCategoryAndOptionsIOS(),setAudioSessionActiveIOS()
Platform compatibility
The README includes a platform compatibility table (not shown in full here), but the library explicitly targets iOS, Android, and web. Some features are platform-specific — for example, languagedetection is Android 14+ only, and speechend is not yet supported on iOS.
Troubleshooting
The README has sections for common Android and iOS issues, but the details aren't included in the excerpt.
In short: This is a cross-platform speech recognition library for React Native/Expo apps. It wraps each platform's native speech APIs behind a unified JavaScript interface, so you can add voice input to your app once and have it work everywhere.
Related
- Project
- Project
- Project
- Project
- Project