You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: android language detection
* register events
* feat: avoid re-sending language detection event if last detected language or confidence don't change
* chore: update docs for language detection
Events are largely based on the [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition). The following events are supported:
|`audiostart`| Audio capturing has started | Includes the `uri` if `recordingOptions.persist` is enabled. |
328
-
|`audioend`| Audio capturing has ended | Includes the `uri` if `recordingOptions.persist` is enabled. |
329
-
|`end`| Speech recognition service has disconnected. | This should always be the last event dispatched, including after errors. |
330
-
|`error`| Fired when a speech recognition error occurs. | You'll also receive an `error` event (with code "aborted") when calling `.abort()`|
331
-
|`nomatch`| Speech recognition service returns a final result with no significant recognition. | You may have non-final results recognized. This may get emitted after cancellation. |
332
-
|`result`| Speech recognition service returns a word or phrase has been positively recognized. | On Android, continous mode runs as a segmented session, meaning when a final result is reached, additional partial and final results will cover a new segment separate from the previous final result. On iOS, you should expect one final result before speech recognition has stopped. |
333
-
|`speechstart`| Fired when any sound — recognizable speech or not — has been detected | On iOS, this will fire once in the session after a result has occurred |
334
-
|`speechend`| Fired when speech recognized by the speech recognition service has stopped being detected. | Not supported yet on iOS |
335
-
|`start`| Speech recognition has started | Use this event to indicate to the user when to speak. |
336
-
|`volumechange`| Fired when the input volume changes. | Returns a value between -2 and 10 indicating the volume of the input audio. Consider anything below 0 to be inaudible. |
|`audiostart`| Audio capturing has started | Includes the `uri` if `recordingOptions.persist` is enabled. |
329
+
|`audioend`| Audio capturing has ended | Includes the `uri` if `recordingOptions.persist` is enabled. |
330
+
|`end`| Speech recognition service has disconnected. | This should always be the last event dispatched, including after errors. |
331
+
|`error`| Fired when a speech recognition error occurs. | You'll also receive an `error` event (with code "aborted") when calling `.abort()`|
332
+
|`nomatch`| Speech recognition service returns a final result with no significant recognition. | You may have non-final results recognized. This may get emitted after cancellation. |
333
+
|`result`| Speech recognition service returns a word or phrase has been positively recognized. | On Android, continous mode runs as a segmented session, meaning when a final result is reached, additional partial and final results will cover a new segment separate from the previous final result. On iOS, you should expect one final result before speech recognition has stopped. |
334
+
|`speechstart`| Fired when any sound — recognizable speech or not — has been detected | On iOS, this will fire once in the session after a result has occurred |
335
+
|`speechend`| Fired when speech recognized by the speech recognition service has stopped being detected. | Not supported yet on iOS |
336
+
|`start`| Speech recognition has started | Use this event to indicate to the user when to speak. |
337
+
|`volumechange`| Fired when the input volume changes. | Returns a value between -2 and 10 indicating the volume of the input audio. Consider anything below 0 to be inaudible. |
338
+
|`languagedetection`| Called when the language detection (and switching) results are available. | Android 14+ only with `com.google.android.as`. Enabled with `EXTRA_ENABLE_LANGUAGE_DETECTION` in the `androidIntent` option when starting. Also can be called multiple times by enabling `EXTRA_ENABLE_LANGUAGE_SWITCH`. |
337
339
338
340
## Handling Errors
339
341
@@ -696,6 +698,39 @@ You may notice that after saying short syllables, words, letters, or numbers (e.
696
698
- For both platforms, you also may want to consider using on-device recognition. On Android this seems to work well for single-word prompts.
697
699
- Alternatively, you may want to consider recording the recognized audio and sending it to an external service for further processing. See [Persisting Audio Recordings](#persisting-audio-recordings) for more information. Note that some services (such as the Google Speech API) may require an audio file with a duration of at least 3 seconds.
698
700
701
+
## Language Detection
702
+
703
+
> [!NOTE]
704
+
> This feature is currently only available on Android 14+ using the `com.google.android.as` service package.
705
+
706
+
You can use the `languagedetection` event to get the detected language and confidence level. This feature has a few requirements:
707
+
708
+
- Android 14+ only.
709
+
- The `com.google.android.as` (on-device recognition) service package must be selected. This seems to be the only service that supports language detection as of writing this.
710
+
- You must enable `EXTRA_ENABLE_LANGUAGE_DETECTION` in the `androidIntentOptions` when starting the recognition.
711
+
- Optional: You can enable `EXTRA_ENABLE_LANGUAGE_SWITCH` to allow the user to switch languages, however **keep in mind that you need the language model to be downloaded for this to work**. Refer to [androidTriggerOfflineModelDownload()](#androidtriggerofflinemodeldownload) to download a model, and [getSupportedLocales()](#getsupportedlocales) to get the list of downloaded on-device locales.
Users on Android devices will first need to download the offline model for the locale they want to use in order to use on-device speech recognition (i.e. the `requiresOnDeviceRecognition` setting in the `start` options).
0 commit comments