android.speech APIs for speech-to-text on Meta Horizon OS. No Meta SDK is required.RECORD_AUDIO and the speech recognition service query as direct children of the <manifest> element:<uses-permission android:name="android.permission.RECORD_AUDIO" />
<queries>
<intent>
<action android:name="android.speech.RecognitionService" />
</intent>
</queries>
RECORD_AUDIO at runtime before starting recognition. The <queries> entry is required for apps that target Android 11 or later. For the runtime permission flow, see Request runtime permissions.| Requirement | Factory and behavior |
|---|---|
Let Horizon OS choose the route | Use SpeechRecognizer.createSpeechRecognizer(context). On Horizon OS v210 or later, this recognizer uses cloud recognition when the device has validated internet access, and uses on-device recognition when offline on Meta VR Glasses, Meta Quest 3, and Meta Quest 3S. |
Keep recognition on the device | On Meta VR Glasses, Meta Quest 3, and Meta Quest 3S, check SpeechRecognizer.isOnDeviceRecognitionAvailable(context), then use SpeechRecognizer.createOnDeviceSpeechRecognizer(context). This route does not send audio to cloud recognition. |
Prefer local recognition with the default factory | Set RecognizerIntent.EXTRA_PREFER_OFFLINE to true. The request returns ERROR_LANGUAGE_NOT_SUPPORTED on devices without on-device recognition. |
isOnDeviceRecognitionAvailable() because createOnDeviceSpeechRecognizer() throws UnsupportedOperationException when the device has no on-device recognizer.SpeechRecognizer on your app’s main thread:val recognizer = if (strictlyOnDevice) {
if (!SpeechRecognizer.isOnDeviceRecognitionAvailable(this)) {
return
}
SpeechRecognizer.createOnDeviceSpeechRecognizer(this)
} else {
SpeechRecognizer.createSpeechRecognizer(this)
}
recognizer.setRecognitionListener(listener)
en-US, en-GB, en-AU, and en-CA) and 23 additional languages:| Language | Primary BCP 47 tag |
|---|---|
Arabic | ar-EG |
Chinese (Simplified) | zh-CN |
Dutch | nl-NL |
English | en-US, en-GB (all regions) |
Filipino (Tagalog) | fil-PH, tl-PH |
Finnish | fi-FI |
French | fr-FR |
German | de-DE |
Hebrew | he-IL |
Hindi | hi-IN |
Indonesian | id-ID |
Italian | it-IT |
Japanese | ja-JP |
Korean | ko-KR |
Malay | ms-MY |
Marathi | mr-IN |
Polish | pl-PL |
Portuguese | pt-BR |
Russian | ru-RU |
Spanish | es-ES |
Swedish | sv-SE |
Tamil | ta-IN |
Thai | th-TH |
Turkish | tr-TR |
es-MX and pt-PT). Chinese supports Simplified Chinese (zh-CN and zh); Traditional Chinese (zh-TW, zh-HK, and zh-Hant) is unsupported on the cloud route.createSpeechRecognizer() transcribes the session in en-US on the active route (cloud or on-device).createOnDeviceSpeechRecognizer() returns ERROR_LANGUAGE_NOT_SUPPORTED.SpeechRecognizer.checkRecognitionSupport() before showing voice controls to confirm language support on the active route. Support queries continue to respond while the device microphone is muted.RecognitionSupport.getOnlineLanguages() returns the supported cloud tags and includes the requested tag when it is a supported regional variant. On the on-device route, RecognitionSupport reports getInstalledOnDeviceLanguages(), getPendingOnDeviceLanguages(), and getSupportedOnDeviceLanguages() for supported languages, and returns ERROR_LANGUAGE_NOT_SUPPORTED for unsupported languages. Call SpeechRecognizer.triggerModelDownload() when a supported on-device language model needs to be downloaded.RecognizerIntent.LANGUAGE_MODEL_FREE_FORM for dictated prose.RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH for search-style text.LANGUAGE_MODEL_FREE_FORM and LANGUAGE_MODEL_WEB_SEARCH select separate models. Cloud requests in the other 23 languages use one model and return lowercase text without punctuation.RecognizerIntent.EXTRA_LANGUAGE with a BCP 47 tag. When EXTRA_LANGUAGE is omitted, cloud recognition uses the device locale and on-device recognition defaults to en-US.val request = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM,
)
putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US")
}
recognizer.startListening(request)
RecognitionListener.onPartialResults() and onResults(). Read the first entry in the string list stored under SpeechRecognizer.RESULTS_RECOGNITION. Partial results replace the previous partial transcript; treat each callback as the current text. If a session ends without a final hypothesis, onResults() delivers the last partial result, which can be an empty string. Treat an empty transcript as a no-result case in your UI.stopListening() when the user finishes speaking and keep waiting for onResults() or onError().cancel() to discard the active request.onResults() or onError() before starting another request.destroy() when the recognizer is no longer needed.ERROR_RECOGNIZER_BUSY or ERROR_CLIENT.RecognitionListener.onError() and keep the retry under user control.| Error | Meaning and response |
|---|---|
ERROR_INSUFFICIENT_PERMISSIONS | The app lacks RECORD_AUDIO, or cloud recognition is unavailable to the user. Request the permission. On Meta VR Glasses, Meta Quest 3, and Meta Quest 3S, retry with on-device recognition when the permission is already granted. |
ERROR_LANGUAGE_NOT_SUPPORTED | The device has no on-device recognizer for an EXTRA_PREFER_OFFLINE request, or createOnDeviceSpeechRecognizer() (or an on-device support or download check) received an unsupported language. Check isOnDeviceRecognitionAvailable() and checkRecognitionSupport() before starting recognition. |
ERROR_LANGUAGE_UNAVAILABLE | The requested on-device language is supported, and its model needs to be downloaded. Call triggerModelDownload(), wait for completion, and let the user retry. |
ERROR_RECOGNIZER_BUSY | Another recognition session is active or the on-device recognizer is still initializing. Wait, then let the user retry. |
ERROR_AUDIO | Audio capture could not start, including while a phone or VoIP call is active. Retry after audio capture becomes available. |
ERROR_NETWORK or ERROR_NETWORK_TIMEOUT | Cloud recognition lost its connection or timed out. Let the user retry or use on-device recognition when available. |
ERROR_SERVER | Cloud recognition could not start, authentication failed, or the recognition service hit another server or provider error. Let the user retry. |
ERROR_CLIENT | The default recognizer is unavailable, the app started an overlapping request, or request preparation failed. End the active request before retrying. |
ERROR_NO_MATCH | Cloud recognition produced no transcript. Let the user try again. On-device silence can instead deliver an empty string through onResults(). |
SpeechRecognizer, RecognizerIntent, and RecognitionListener.