expo-speech-recognition 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +185 -52
- package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechRecognitionOptions.kt +3 -0
- package/build/ExpoSpeechRecognitionModule.types.d.ts +22 -4
- package/build/ExpoSpeechRecognitionModule.types.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.types.js.map +1 -1
- package/ios/EXSpeechRecognitionPermissionRequester.swift +5 -2
- package/ios/ExpoSpeechRecognitionModule.swift +3 -3
- package/ios/ExpoSpeechRecognizer.swift +17 -5
- package/ios/SpeechRecognitionOptions.swift +3 -0
- package/ios/SpeechRecognizerRequester.swift +3 -2
- package/package.json +4 -4
- package/src/ExpoSpeechRecognitionModule.types.ts +24 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# expo-speech-recognition
|
|
2
2
|
|
|
3
|
+
## 2.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- dd8d0dd: Fix: restricted speech recognition permissions for iOS will now be classified as "denied" instead of "undetermined"
|
|
8
|
+
|
|
9
|
+
You can now use `restricted` to check whether the Speech Recognition permission is restricted:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const permissions =
|
|
13
|
+
await ExpoSpeechRecognitionModule.requestPermissionsAsync();
|
|
14
|
+
if (!permissions.granted) {
|
|
15
|
+
if (permissions.restricted) {
|
|
16
|
+
// Ask user to enable speech recognition on their device, either in:
|
|
17
|
+
// Settings -> Screen Time -> Content & Privacy Restrictions -> Speech Recognition
|
|
18
|
+
// or Settings -> General -> VPN & Device Management
|
|
19
|
+
// (if it is part of a MDM profile, see: https://support.apple.com/en-us/guide/deployment/depc0aadd3fe/web)
|
|
20
|
+
} else {
|
|
21
|
+
// Ask user to enable speech recognition for your app
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 2.1.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- c6cb064: Added `iosVoiceProcessingEnabled` option to prevent microphone feedback from speakers for iOS
|
|
32
|
+
|
|
3
33
|
## 2.0.0
|
|
4
34
|
|
|
5
35
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -51,6 +51,9 @@ expo-speech-recognition implements the iOS [`SFSpeechRecognizer`](https://develo
|
|
|
51
51
|
- [setCategoryIOS()](#setcategoryios-void-ios-only)
|
|
52
52
|
- [getAudioSessionCategoryAndOptionsIOS()](#getaudiosessioncategoryandoptionsios-ios-only)
|
|
53
53
|
- [setAudioSessionActiveIOS()](#setaudiosessionactiveiosvalue-boolean-options--notifyothersondeactivation-boolean--void)
|
|
54
|
+
- [System Overview Diagrams](#system-overview-diagrams)
|
|
55
|
+
- [Overall Architecture](#overall-architecture)
|
|
56
|
+
- [Event Flow](#event-flow)
|
|
54
57
|
|
|
55
58
|
## Installation
|
|
56
59
|
|
|
@@ -195,6 +198,7 @@ import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
|
195
198
|
ExpoSpeechRecognitionModule.getPermissionsAsync().then((result) => {
|
|
196
199
|
console.log("Status:", result.status);
|
|
197
200
|
console.log("Granted:", result.granted);
|
|
201
|
+
console.log("Restricted:", result.restricted); // (iOS only)
|
|
198
202
|
console.log("Can ask again:", result.canAskAgain);
|
|
199
203
|
console.log("Expires:", result.expires);
|
|
200
204
|
});
|
|
@@ -279,6 +283,9 @@ ExpoSpeechRecognitionModule.start({
|
|
|
279
283
|
categoryOptions: ["defaultToSpeaker", "allowBluetooth"],
|
|
280
284
|
mode: "measurement",
|
|
281
285
|
},
|
|
286
|
+
// [Default: false] Does extra audio processing to prevent
|
|
287
|
+
// microphone feedback from speakers
|
|
288
|
+
iosVoiceProcessingEnabled: true,
|
|
282
289
|
// [Default: undefined] Recording options for Android & iOS
|
|
283
290
|
// Android 13+ and iOS only.
|
|
284
291
|
recordingOptions: {
|
|
@@ -333,7 +340,11 @@ ExpoSpeechRecognitionModule.abort();
|
|
|
333
340
|
|
|
334
341
|
## Speech Recognition Events
|
|
335
342
|
|
|
336
|
-
Events are largely based on the [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition).
|
|
343
|
+
Events are largely based on the [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition).
|
|
344
|
+
|
|
345
|
+
View the [event flow diagram here](#event-flow).
|
|
346
|
+
|
|
347
|
+
The following events are supported:
|
|
337
348
|
|
|
338
349
|
| Event Name | Description | Notes |
|
|
339
350
|
| ------------------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -649,7 +660,7 @@ recognition.onresult = (event) => {
|
|
|
649
660
|
const handleStart = (event: Event) => console.log("started!");
|
|
650
661
|
recognition.registerEventListener("start", handleStart);
|
|
651
662
|
// and remember to unregister after you're done:
|
|
652
|
-
recognition.
|
|
663
|
+
recognition.removeEventListener("start", handleStart);
|
|
653
664
|
|
|
654
665
|
const handleResult = (event: SpeechRecognitionEvent) => {
|
|
655
666
|
console.log("result:", event.results[event.resultIndex][0].transcript);
|
|
@@ -755,13 +766,17 @@ As of 7 Aug 2024, the following platforms are supported:
|
|
|
755
766
|
| Safari Desktop >= v16 | ✅ | Siri | Implemented via prefix `webkitSpeechRecognition`. Siri needs to be enabled |
|
|
756
767
|
| Chrome on Android | ✅ | Google | There's a few differences in how results get handled in comparison to the Chrome Desktop implementation |
|
|
757
768
|
| Chrome on iOS | ❌ | Google | Not working (Last tested 2023) |
|
|
758
|
-
| Edge on Windows | (unknown) | Azure | SpeechRecognition API is implemented, but requires the Azure speech component. Verify it
|
|
759
|
-
| Edge on Mac ARM | ❌ | Azure | SpeechRecognition API is implemented, but requires the Azure speech component. Verify it
|
|
769
|
+
| Edge on Windows | (unknown) | Azure | SpeechRecognition API is implemented, but requires the Azure speech component. Verify it's presence at `edge://components` |
|
|
770
|
+
| Edge on Mac ARM | ❌ | Azure | SpeechRecognition API is implemented, but requires the Azure speech component. Verify it's presence at `edge://components` |
|
|
760
771
|
| Brave Desktop | ❌ | - | As of Aug 2024, Brave is working on an implementation however there's currently no ETA (source: [brave-browser/issues/3725](https://github.com/brave/brave-browser/issues/3725#issuecomment-2224068859)) |
|
|
761
772
|
| Firefox Desktop | ❌ | - | No SpeechRecognition implementation |
|
|
762
773
|
|
|
763
774
|
## Common Troubleshooting Issues
|
|
764
775
|
|
|
776
|
+
### Speaker is getting picked up by the microphone
|
|
777
|
+
|
|
778
|
+
If you're experiencing feedback from the speakers, you may want to consider enabling the `iosVoiceProcessingEnabled` option when starting speech recognition. This option adds additional signal processing to your microphone and output.
|
|
779
|
+
|
|
765
780
|
### Android issues
|
|
766
781
|
|
|
767
782
|
#### Single words/letters/characters not recognized
|
|
@@ -794,6 +809,20 @@ If you're running a multimedia application with audio or video playback, you'll
|
|
|
794
809
|
- `ExpoSpeechRecognitionModule.start({ iosCategory })` to configure the audio session category and mode when speech recognition starts
|
|
795
810
|
- `setAudioCategoryIOS({ category, categoryOptions, mode })` to set the audio session category and mode at a later point in time
|
|
796
811
|
|
|
812
|
+
#### Permissions issues even though the app is explicitly allowed in Settings
|
|
813
|
+
|
|
814
|
+
If the user has explicitly allowed your app **Microphone** and **Speech Recognition** permissions (under Settings > Apps > [your app]), this likely has something to do with the Speech Recognition permission.
|
|
815
|
+
|
|
816
|
+
For a quick fix, you could enable `requiresOnDeviceSpeechRecognition` so that you don't use network-based speech recognition (and therefore don't need Speech Recognition permissions). You should also switch to using the [`requestMicrophonePermissionsAsync()`](#requestmicrophonepermissionsasync) function instead, which only requests the microphone permissions instead of both microphone and speech recognition. Android doesn't have a dedicated speech recognition permission so it's safe to only request microphone permissions on both Android and iOS. Keep in mind though that the `requiresOnDeviceSpeechRecognition` setting for Android will require the language model to be installed.
|
|
817
|
+
|
|
818
|
+
However, to diagnose the underlying issue:
|
|
819
|
+
|
|
820
|
+
- Whether the user has enabled Content & Privacy Restrictions for Speech Recognition on their iOS device (Settings > Screen Time > Content & Privacy Restrictions > Speech Recognition)
|
|
821
|
+
- Remedy: Add, or disable the app from the list of apps under Speech Recognition
|
|
822
|
+
- Whether the user is part of a Mobile device management (MDM) profile. This could make the speech recognition `restricted` (you can check for this in with the [`getPermissionsAsync()`](#getpermissionsasync) and [`requestPermissionsAsync()`](#requestpermissionsasync) APIs). To check for this, open Settings > General > VPN & Device Management.
|
|
823
|
+
- Remedy: If the user is part of a managed profile, ask the MDM administrator (usually your work) to update the [Privacy Preferences Policy Control payload settings](https://support.apple.com/en-us/guide/deployment/dep38df53c2a/web) to allow your app to use speech recognition.
|
|
824
|
+
- As usual, after changing any of these kinds of settings in the Settings app, a reboot may just "fix" it
|
|
825
|
+
|
|
797
826
|
## API Methods
|
|
798
827
|
|
|
799
828
|
### `start(options: SpeechRecognitionOptions): void`
|
|
@@ -813,8 +842,6 @@ ExpoSpeechRecognitionModule.start({
|
|
|
813
842
|
Stops speech recognition and attempts to return a final result (through the `result` event).
|
|
814
843
|
|
|
815
844
|
```ts
|
|
816
|
-
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
817
|
-
|
|
818
845
|
ExpoSpeechRecognitionModule.stop();
|
|
819
846
|
// Expect the following events to be emitted in order:
|
|
820
847
|
// One of:
|
|
@@ -830,10 +857,10 @@ ExpoSpeechRecognitionModule.stop();
|
|
|
830
857
|
Immediately cancels speech recognition (does not process the final result).
|
|
831
858
|
|
|
832
859
|
```ts
|
|
833
|
-
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
834
|
-
|
|
835
860
|
ExpoSpeechRecognitionModule.abort();
|
|
836
|
-
// Expect
|
|
861
|
+
// Expect the following events to be emitted in order:
|
|
862
|
+
// - "error" event with the code "aborted"
|
|
863
|
+
// - "end" event indicating speech recognition has finished
|
|
837
864
|
```
|
|
838
865
|
|
|
839
866
|
### `requestPermissionsAsync()`
|
|
@@ -848,11 +875,10 @@ If you're using on-device recognition on iOS, you just need to request microphon
|
|
|
848
875
|
Once a user has granted (or denied) permissions by responding to the original permission request dialog, the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
849
876
|
|
|
850
877
|
```ts
|
|
851
|
-
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
852
|
-
|
|
853
878
|
ExpoSpeechRecognitionModule.requestPermissionsAsync().then((result) => {
|
|
854
879
|
console.log("Status:", result.status); // "granted" | "denied" | "not-determined"
|
|
855
880
|
console.log("Granted:", result.granted); // true | false
|
|
881
|
+
console.log("Restricted:", result.restricted); // true | false | undefined (iOS only)
|
|
856
882
|
console.log("Can ask again:", result.canAskAgain); // true | false
|
|
857
883
|
console.log("Expires:", result.expires); // "never" | number
|
|
858
884
|
});
|
|
@@ -866,8 +892,6 @@ Requests permissions to use the microphone.
|
|
|
866
892
|
- On Android, this requests [`RECORD_AUDIO`](https://developer.android.com/reference/android/Manifest.permission#RECORD_AUDIO) permissions.
|
|
867
893
|
|
|
868
894
|
```ts
|
|
869
|
-
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
870
|
-
|
|
871
895
|
ExpoSpeechRecognitionModule.requestMicrophonePermissionsAsync().then(
|
|
872
896
|
(result) => {
|
|
873
897
|
console.log("Status:", result.status); // "granted" | "denied" | "not-determined"
|
|
@@ -897,6 +921,7 @@ if (!requiresOnDeviceRecognition && Platform.OS === "ios") {
|
|
|
897
921
|
(result) => {
|
|
898
922
|
console.log("Status:", result.status); // "granted" | "denied" | "not-determined"
|
|
899
923
|
console.log("Granted:", result.granted); // true | false
|
|
924
|
+
console.log("Restricted:", result.restricted); // true | false | undefined (iOS only)
|
|
900
925
|
console.log("Can ask again:", result.canAskAgain); // true | false
|
|
901
926
|
console.log("Expires:", result.expires); // "never" | number
|
|
902
927
|
},
|
|
@@ -909,11 +934,10 @@ if (!requiresOnDeviceRecognition && Platform.OS === "ios") {
|
|
|
909
934
|
Returns the current permission status for both microphone and iOS speech recognizer.
|
|
910
935
|
|
|
911
936
|
```ts
|
|
912
|
-
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
913
|
-
|
|
914
937
|
ExpoSpeechRecognitionModule.getPermissionsAsync().then((result) => {
|
|
915
938
|
console.log("Status:", result.status); // "granted" | "denied" | "not-determined"
|
|
916
939
|
console.log("Granted:", result.granted); // true | false
|
|
940
|
+
console.log("Restricted:", result.restricted); // true | false | undefined (iOS only)
|
|
917
941
|
console.log("Can ask again:", result.canAskAgain); // true | false
|
|
918
942
|
console.log("Expires:", result.expires); // "never" | number
|
|
919
943
|
});
|
|
@@ -924,8 +948,6 @@ ExpoSpeechRecognitionModule.getPermissionsAsync().then((result) => {
|
|
|
924
948
|
Returns the current permission status for the microphone. On Android, this checks the [`RECORD_AUDIO`](https://developer.android.com/reference/android/Manifest.permission#RECORD_AUDIO) permissions. On iOS this checks the [`AVAudioSession.RecordPermission`](https://developer.apple.com/documentation/avfaudio/avaudiosession/recordpermission) permissions.
|
|
925
949
|
|
|
926
950
|
```ts
|
|
927
|
-
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
928
|
-
|
|
929
951
|
ExpoSpeechRecognitionModule.getMicrophonePermissionsAsync().then((result) => {
|
|
930
952
|
console.log("Status:", result.status); // "granted" | "denied" | "not-determined"
|
|
931
953
|
console.log("Granted:", result.granted); // true | false
|
|
@@ -942,12 +964,11 @@ ExpoSpeechRecognitionModule.getMicrophonePermissionsAsync().then((result) => {
|
|
|
942
964
|
Checks the current permissions to use network-based recognition for [`SFSpeechRecognizer`](https://developer.apple.com/documentation/speech/sfspeechrecognizer) for iOS.
|
|
943
965
|
|
|
944
966
|
```ts
|
|
945
|
-
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
946
|
-
|
|
947
967
|
ExpoSpeechRecognitionModule.getSpeechRecognizerPermissionsAsync().then(
|
|
948
968
|
(result) => {
|
|
949
969
|
console.log("Status:", result.status); // "granted" | "denied" | "not-determined"
|
|
950
970
|
console.log("Granted:", result.granted); // true | false
|
|
971
|
+
console.log("Restricted:", result.restricted); // true | false | undefined (iOS only)
|
|
951
972
|
console.log("Can ask again:", result.canAskAgain); // true | false
|
|
952
973
|
console.log("Expires:", result.expires); // "never" | number
|
|
953
974
|
},
|
|
@@ -959,8 +980,6 @@ ExpoSpeechRecognitionModule.getSpeechRecognizerPermissionsAsync().then(
|
|
|
959
980
|
Returns the current internal state of the speech recognizer.
|
|
960
981
|
|
|
961
982
|
```ts
|
|
962
|
-
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
963
|
-
|
|
964
983
|
// Note: you probably should rather rely on the events emitted by the SpeechRecognition API instead
|
|
965
984
|
ExpoSpeechRecognitionModule.getStateAsync().then((state) => {
|
|
966
985
|
console.log("Current state:", state);
|
|
@@ -976,9 +995,7 @@ ExpoSpeechRecognitionModule.getStateAsync().then((state) => {
|
|
|
976
995
|
Get the list of supported locales and the installed locales that can be used for on-device speech recognition.
|
|
977
996
|
|
|
978
997
|
```ts
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
getSupportedLocales({
|
|
998
|
+
ExpoSpeechRecognitionModule.getSupportedLocales({
|
|
982
999
|
/**
|
|
983
1000
|
* The package name of the speech recognition service to use.
|
|
984
1001
|
* If not provided, the default service used for on-device recognition will be used.
|
|
@@ -1012,9 +1029,7 @@ Get list of speech recognition services available on the device.
|
|
|
1012
1029
|
> This only includes services that are listed under `androidSpeechServicePackages` in your app.json as well as the core services listed under `forceQueryable` when running the command: `adb shell dumpsys package queries`
|
|
1013
1030
|
|
|
1014
1031
|
```ts
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
const packages = getSpeechRecognitionServices();
|
|
1032
|
+
const packages = ExpoSpeechRecognitionModule.getSpeechRecognitionServices();
|
|
1018
1033
|
console.log("Speech recognition services:", packages.join(", "));
|
|
1019
1034
|
// e.g. ["com.google.android.as", "com.google.android.tts", "com.samsung.android.bixby.agent"]
|
|
1020
1035
|
```
|
|
@@ -1024,9 +1039,7 @@ console.log("Speech recognition services:", packages.join(", "));
|
|
|
1024
1039
|
Returns the default voice recognition service on the device.
|
|
1025
1040
|
|
|
1026
1041
|
```ts
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
const service = getDefaultRecognitionService();
|
|
1042
|
+
const service = ExpoSpeechRecognitionModule.getDefaultRecognitionService();
|
|
1030
1043
|
console.log("Default recognition service:", service.packageName);
|
|
1031
1044
|
// Usually this is "com.google.android.tts" on Android 13+ and "com.google.android.googlequicksearchbox" on Android <=12.
|
|
1032
1045
|
// For on-device recognition, "com.google.android.as" will likely be used.
|
|
@@ -1037,9 +1050,7 @@ console.log("Default recognition service:", service.packageName);
|
|
|
1037
1050
|
Returns the default voice assistant service on the device.
|
|
1038
1051
|
|
|
1039
1052
|
```ts
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
const service = getAssistantService();
|
|
1053
|
+
const service = ExpoSpeechRecognitionModule.getAssistantService();
|
|
1043
1054
|
console.log("Default assistant service:", service.packageName);
|
|
1044
1055
|
// Usually "com.google.android.googlequicksearchbox" for Google
|
|
1045
1056
|
// or "com.samsung.android.bixby.agent" for Samsung
|
|
@@ -1054,9 +1065,7 @@ If this method returns false, calling `start()` will fail and emit an error even
|
|
|
1054
1065
|
For Web, this method only checks if the browser has the Web SpeechRecognition API available, however keep in mind that browsers (like Brave) may still have the APIs but not have it implemented yet. Refer to [Platform Compatibility Table](#platform-compatibility-table) for more information. You may want to use a user agent parser to fill in the gaps.
|
|
1055
1066
|
|
|
1056
1067
|
```ts
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
const available = isRecognitionAvailable();
|
|
1068
|
+
const available = ExpoSpeechRecognitionModule.isRecognitionAvailable();
|
|
1060
1069
|
console.log("Speech recognition available:", available);
|
|
1061
1070
|
```
|
|
1062
1071
|
|
|
@@ -1065,9 +1074,7 @@ console.log("Speech recognition available:", available);
|
|
|
1065
1074
|
Whether the device supports on-device speech recognition.
|
|
1066
1075
|
|
|
1067
1076
|
```ts
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
const available = supportsOnDeviceRecognition();
|
|
1077
|
+
const available = ExpoSpeechRecognitionModule.supportsOnDeviceRecognition();
|
|
1071
1078
|
console.log("OnDevice recognition available:", available);
|
|
1072
1079
|
```
|
|
1073
1080
|
|
|
@@ -1076,9 +1083,7 @@ console.log("OnDevice recognition available:", available);
|
|
|
1076
1083
|
Whether audio recording is supported during speech recognition. This mostly applies to Android devices, to check if it's at least Android 13.
|
|
1077
1084
|
|
|
1078
1085
|
```ts
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
const available = supportsRecording();
|
|
1086
|
+
const available = ExpoSpeechRecognitionModule.supportsRecording();
|
|
1082
1087
|
console.log("Recording available:", available);
|
|
1083
1088
|
```
|
|
1084
1089
|
|
|
@@ -1091,10 +1096,8 @@ You can see which locales are supported and installed on your device by running
|
|
|
1091
1096
|
To download the offline model for a specific locale, use the `androidTriggerOfflineModelDownload` function.
|
|
1092
1097
|
|
|
1093
1098
|
```ts
|
|
1094
|
-
import { androidTriggerOfflineModelDownload } from "expo-speech-recognition";
|
|
1095
|
-
|
|
1096
1099
|
// Download the offline model for the specified locale
|
|
1097
|
-
androidTriggerOfflineModelDownload({
|
|
1100
|
+
ExpoSpeechRecognitionModule.androidTriggerOfflineModelDownload({
|
|
1098
1101
|
locale: "en-US",
|
|
1099
1102
|
})
|
|
1100
1103
|
.then((result) => {
|
|
@@ -1130,13 +1133,13 @@ This function is an implementation of [AVAudioSession.setCategory](https://devel
|
|
|
1130
1133
|
|
|
1131
1134
|
```ts
|
|
1132
1135
|
import {
|
|
1133
|
-
|
|
1136
|
+
ExpoSpeechRecognitionModule,
|
|
1134
1137
|
AVAudioSessionCategory,
|
|
1135
1138
|
AVAudioSessionCategoryOptions,
|
|
1136
1139
|
AVAudioSessionMode,
|
|
1137
1140
|
} from "expo-speech-recognition";
|
|
1138
1141
|
|
|
1139
|
-
setCategoryIOS({
|
|
1142
|
+
ExpoSpeechRecognitionModule.setCategoryIOS({
|
|
1140
1143
|
category: AVAudioSessionCategory.playAndRecord, // or "playAndRecord"
|
|
1141
1144
|
categoryOptions: [
|
|
1142
1145
|
AVAudioSessionCategoryOptions.defaultToSpeaker,
|
|
@@ -1151,9 +1154,9 @@ setCategoryIOS({
|
|
|
1151
1154
|
Returns the current audio session category and options. For advanced use cases, you may want to use this function to safely configure the audio session category and mode.
|
|
1152
1155
|
|
|
1153
1156
|
```ts
|
|
1154
|
-
|
|
1157
|
+
const values =
|
|
1158
|
+
ExpoSpeechRecognitionModule.getAudioSessionCategoryAndOptionsIOS();
|
|
1155
1159
|
|
|
1156
|
-
const values = getAudioSessionCategoryAndOptionsIOS();
|
|
1157
1160
|
console.log(values);
|
|
1158
1161
|
// { category: "playAndRecord", categoryOptions: ["defaultToSpeaker", "allowBluetooth"], mode: "measurement" }
|
|
1159
1162
|
```
|
|
@@ -1163,9 +1166,139 @@ console.log(values);
|
|
|
1163
1166
|
Sets the audio session active state.
|
|
1164
1167
|
|
|
1165
1168
|
```ts
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
setAudioSessionActiveIOS(true, {
|
|
1169
|
+
ExpoSpeechRecognitionModule.setAudioSessionActiveIOS(true, {
|
|
1169
1170
|
notifyOthersOnDeactivation: true,
|
|
1170
1171
|
});
|
|
1171
1172
|
```
|
|
1173
|
+
|
|
1174
|
+
## System Overview Diagrams
|
|
1175
|
+
|
|
1176
|
+
### Overall Architecture
|
|
1177
|
+
|
|
1178
|
+
```mermaid
|
|
1179
|
+
graph TB
|
|
1180
|
+
|
|
1181
|
+
subgraph "JavaScript Layer"
|
|
1182
|
+
HOOK[useSpeechRecognitionEvent Hook]
|
|
1183
|
+
MODULE[ExpoSpeechRecognitionModule]
|
|
1184
|
+
WEB[ExpoWebSpeechRecognition]
|
|
1185
|
+
|
|
1186
|
+
WEB_NOTE[Note: Only for polyfilling<br/>external libraries that use<br/>the Web Speech API]
|
|
1187
|
+
|
|
1188
|
+
BROWSER[ExpoWebSpeechRecognition.ts]
|
|
1189
|
+
end
|
|
1190
|
+
|
|
1191
|
+
subgraph "Platform Bridges"
|
|
1192
|
+
EXPO[Expo Modules Core]
|
|
1193
|
+
end
|
|
1194
|
+
|
|
1195
|
+
subgraph "iOS Native"
|
|
1196
|
+
IOS_MOD[ExpoSpeechRecognitionModule.swift]
|
|
1197
|
+
IOS_REC[ExpoSpeechRecognizer.swift]
|
|
1198
|
+
SF[SFSpeechRecognizer]
|
|
1199
|
+
AVAUDIO[AVAudioEngine]
|
|
1200
|
+
end
|
|
1201
|
+
|
|
1202
|
+
subgraph "Android Native"
|
|
1203
|
+
AND_MOD[ExpoSpeechRecognitionModule.kt]
|
|
1204
|
+
AND_SVC[ExpoSpeechService.kt]
|
|
1205
|
+
ANDROID_SR[Android SpeechRecognizer]
|
|
1206
|
+
AUDIO_REC[ExpoAudioRecorder]
|
|
1207
|
+
end
|
|
1208
|
+
|
|
1209
|
+
subgraph "Web"
|
|
1210
|
+
WEB_MOD[ExpoSpeechRecognitionModule.web.ts]
|
|
1211
|
+
end
|
|
1212
|
+
|
|
1213
|
+
HOOK --> MODULE
|
|
1214
|
+
MODULE --> EXPO
|
|
1215
|
+
|
|
1216
|
+
EXPO --> IOS_MOD
|
|
1217
|
+
EXPO --> AND_MOD
|
|
1218
|
+
EXPO --> WEB_MOD
|
|
1219
|
+
|
|
1220
|
+
IOS_MOD --> IOS_REC
|
|
1221
|
+
IOS_REC --> SF
|
|
1222
|
+
IOS_REC --> AVAUDIO
|
|
1223
|
+
|
|
1224
|
+
AND_MOD --> AND_SVC
|
|
1225
|
+
AND_SVC --> ANDROID_SR
|
|
1226
|
+
AND_SVC --> AUDIO_REC
|
|
1227
|
+
|
|
1228
|
+
WEB --> BROWSER
|
|
1229
|
+
BROWSER -.- WEB_NOTE
|
|
1230
|
+
|
|
1231
|
+
style MODULE fill:#f3e5f5,color:#000000
|
|
1232
|
+
style IOS_MOD fill:#e8f5e8,color:#000000
|
|
1233
|
+
style AND_MOD fill:#fff3e0,color:#000000
|
|
1234
|
+
style WEB fill:#fce4ec,color:#000000
|
|
1235
|
+
style WEB_MOD fill:#e1f5fe,color:#000000
|
|
1236
|
+
style WEB_NOTE fill:#fff9c4,color:#000000
|
|
1237
|
+
```
|
|
1238
|
+
|
|
1239
|
+
### Event Flow
|
|
1240
|
+
|
|
1241
|
+
#### Non-continuous recognition
|
|
1242
|
+
|
|
1243
|
+
```mermaid
|
|
1244
|
+
sequenceDiagram
|
|
1245
|
+
participant App as React Native App
|
|
1246
|
+
participant Module as ExpoSpeechRecognitionModule
|
|
1247
|
+
participant Native as Native Platform
|
|
1248
|
+
participant Engine as Speech Engine (e.g. Siri, Google)
|
|
1249
|
+
|
|
1250
|
+
App->>Module: start(options)
|
|
1251
|
+
Module->>Native: Initialize speech recognizer
|
|
1252
|
+
Native->>Engine: Setup recognition service
|
|
1253
|
+
|
|
1254
|
+
Native->>App: emit("start")
|
|
1255
|
+
Native->>App: emit("audiostart")
|
|
1256
|
+
|
|
1257
|
+
loop Speech Recognition
|
|
1258
|
+
Engine->>Native: Audio data captured
|
|
1259
|
+
|
|
1260
|
+
Note over App,Native: "volumechange" events only occur if user has opted in
|
|
1261
|
+
Native->>App: emit("volumechange", {value})
|
|
1262
|
+
Engine->>Native: Partial results
|
|
1263
|
+
Note over App,Native: "result" {isFinal: false} only occur when interimResults is enabled
|
|
1264
|
+
Native->>App: emit("result", {results, isFinal: false})
|
|
1265
|
+
end
|
|
1266
|
+
|
|
1267
|
+
Engine->>Native: Final result
|
|
1268
|
+
Native->>App: emit("result", {results, isFinal: true})
|
|
1269
|
+
Native->>App: emit("audioend")
|
|
1270
|
+
Native->>App: emit("end")
|
|
1271
|
+
```
|
|
1272
|
+
|
|
1273
|
+
#### Continuous recognition
|
|
1274
|
+
|
|
1275
|
+
```mermaid
|
|
1276
|
+
sequenceDiagram
|
|
1277
|
+
participant App as React Native App
|
|
1278
|
+
participant Module as ExpoSpeechRecognitionModule
|
|
1279
|
+
participant Native as Native Platform
|
|
1280
|
+
participant Engine as Speech Engine (e.g. Siri, Google)
|
|
1281
|
+
|
|
1282
|
+
App->>Module: start(options)
|
|
1283
|
+
Module->>Native: Initialize speech recognizer
|
|
1284
|
+
Native->>Engine: Setup recognition service
|
|
1285
|
+
|
|
1286
|
+
Native->>App: emit("start")
|
|
1287
|
+
Native->>App: emit("audiostart")
|
|
1288
|
+
|
|
1289
|
+
loop Speech Recognition Segment
|
|
1290
|
+
loop Interim Results (Volatile)
|
|
1291
|
+
Note over App,Engine: Partial results cover new segments
|
|
1292
|
+
Note over App,Engine: You may want to concatenate with the previous final result
|
|
1293
|
+
Engine->>Native: Partial results
|
|
1294
|
+
Native->>App: emit("result", {results, isFinal: false})
|
|
1295
|
+
end
|
|
1296
|
+
|
|
1297
|
+
Note over App,Engine: Final results cover new segments and are new utterances
|
|
1298
|
+
Engine->>Native: Final result
|
|
1299
|
+
Native->>App: emit("result", {results, isFinal: true})
|
|
1300
|
+
end
|
|
1301
|
+
|
|
1302
|
+
Native->>App: emit("audioend")
|
|
1303
|
+
Native->>App: emit("end")
|
|
1304
|
+
```
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import type { PermissionResponse } from "expo-modules-core";
|
|
2
2
|
import type { NativeModule } from "expo";
|
|
3
|
+
export type ExpoSpeechRecognitionPermissionResponse = PermissionResponse & {
|
|
4
|
+
/**
|
|
5
|
+
* Whether the speech recognition is restricted by Content & Privacy Restrictions.
|
|
6
|
+
*
|
|
7
|
+
* This value corresponds to the `restricted` enum of `SFSpeechRecognizer.authorizationStatus()`.
|
|
8
|
+
*
|
|
9
|
+
* This is only available on iOS.
|
|
10
|
+
*/
|
|
11
|
+
restricted?: boolean;
|
|
12
|
+
};
|
|
3
13
|
import type { AudioEncodingAndroid, AVAudioSessionCategory, AVAudioSessionCategoryOptions, AVAudioSessionMode, RecognizerIntentEnableLanguageSwitch, RecognizerIntentExtraLanguageModel, TaskHintIOS } from "./constants";
|
|
4
14
|
export type AVAudioSessionCategoryValue = (typeof AVAudioSessionCategory)[keyof typeof AVAudioSessionCategory];
|
|
5
15
|
export type ExpoSpeechRecognitionResult = {
|
|
@@ -256,6 +266,14 @@ export type ExpoSpeechRecognitionOptions = {
|
|
|
256
266
|
*/
|
|
257
267
|
intervalMillis?: number;
|
|
258
268
|
};
|
|
269
|
+
/**
|
|
270
|
+
* [iOS only] Enabling this option will prevent microphone feedback.
|
|
271
|
+
*
|
|
272
|
+
* When enabled, extra signal processing is applied on the incoming audio, and any audio that is coming from the device is taken out.
|
|
273
|
+
*
|
|
274
|
+
* (This option will place both input and output nodes in voice processing mode as noted in Apple docs: http://developer.apple.com/videos/play/wwdc2019/510/?time=66)
|
|
275
|
+
*/
|
|
276
|
+
iosVoiceProcessingEnabled?: boolean;
|
|
259
277
|
};
|
|
260
278
|
export type IOSTaskHintValue = (typeof TaskHintIOS)[keyof typeof TaskHintIOS];
|
|
261
279
|
export type RecordingOptions = {
|
|
@@ -525,13 +543,13 @@ export declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSp
|
|
|
525
543
|
* Once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
526
544
|
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
527
545
|
*/
|
|
528
|
-
requestPermissionsAsync(): Promise<
|
|
546
|
+
requestPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;
|
|
529
547
|
/**
|
|
530
548
|
* Returns the current permission status for speech recognition and the microphone.
|
|
531
549
|
*
|
|
532
550
|
* You may also use `getMicrophonePermissionsAsync` and `getSpeechRecognizerPermissionsAsync` to get the permissions separately.
|
|
533
551
|
*/
|
|
534
|
-
getPermissionsAsync(): Promise<
|
|
552
|
+
getPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;
|
|
535
553
|
/**
|
|
536
554
|
* Returns the current permission status for the microphone.
|
|
537
555
|
*/
|
|
@@ -546,7 +564,7 @@ export declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSp
|
|
|
546
564
|
/**
|
|
547
565
|
* Returns the current permission status for speech recognition.
|
|
548
566
|
*/
|
|
549
|
-
getSpeechRecognizerPermissionsAsync(): Promise<
|
|
567
|
+
getSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;
|
|
550
568
|
/**
|
|
551
569
|
* [iOS only] Presents a dialog to the user to request permissions for using the speech recognizer.
|
|
552
570
|
* This permission is required when `requiresOnDeviceRecognition` is disabled (i.e. network-based recognition)
|
|
@@ -554,7 +572,7 @@ export declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSp
|
|
|
554
572
|
* For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
555
573
|
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
556
574
|
*/
|
|
557
|
-
requestSpeechRecognizerPermissionsAsync(): Promise<
|
|
575
|
+
requestSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;
|
|
558
576
|
/**
|
|
559
577
|
* Returns an array of locales supported by the speech recognizer.
|
|
560
578
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSpeechRecognitionModule.types.d.ts","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,oCAAoC,EACpC,kCAAkC,EAClC,WAAW,EACZ,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,2BAA2B,GACrC,CAAC,OA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AC;IACrD;;;;OAIG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EACV,wCAAwC,GACxC,+CAA+C,GAC/C,kCAAkC,CAAC;IAEvC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;IAEjC;;OAEG;IACH,wBAAwB,CAAC,EAAE;QACzB;;;;WAIG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB;;;;;;WAMG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpoSpeechRecognitionModule.types.d.ts","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,MAAM,MAAM,uCAAuC,GAAG,kBAAkB,GAAG;IACzE;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,oCAAoC,EACpC,kCAAkC,EAClC,WAAW,EACZ,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,2BAA2B,GACrC,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAC;AAEvE,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,EAAE,kCAAkC,EAAE,CAAC;CAChD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["../src/ExpoSpeechRecognitionModule.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionResponse } from \"expo-modules-core\";\nimport type { NativeModule } from \"expo\";\n\nimport type {\n AudioEncodingAndroid,\n AVAudioSessionCategory,\n AVAudioSessionCategoryOptions,\n AVAudioSessionMode,\n RecognizerIntentEnableLanguageSwitch,\n RecognizerIntentExtraLanguageModel,\n TaskHintIOS,\n} from \"./constants\";\n\nexport type AVAudioSessionCategoryValue =\n (typeof AVAudioSessionCategory)[keyof typeof AVAudioSessionCategory];\n\nexport type ExpoSpeechRecognitionResult = {\n transcript: string;\n /**\n * Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating transcript confidence.\n */\n confidence: number;\n /**\n * An array of transcription segments that represent the parts of the transcription, as identified by the speech recognizer.\n *\n * Notes for Android:\n *\n * - This is only available for SDK 34+ (Android 14+)\n * - This is only verified to work with the `com.google.android.as` service (using on device speech recognition)\n * - Segments are only available during the final result\n * - The segment parts are split up by words.\n * - The segments are only available for the first transcript\n * - Segment confidences currently return as -1 (unavailable)\n *\n * Notes for iOS:\n *\n * - The confidence value will be 0 on partial results\n */\n segments: ExpoSpeechRecognitionResultSegment[];\n};\n\nexport type ExpoSpeechRecognitionResultSegment = {\n /** The start timestamp of the utterance, e.g. 1000 */\n startTimeMillis: number;\n /** The end timestamp of the utterance, e.g. 1500 */\n endTimeMillis: number;\n /** The text portion of the transcript, e.g. \"Hello world\" */\n segment: string;\n /** Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating the confidence of the specific segment */\n confidence: number;\n};\n\n/** Fired when there's a speech result. The result may be partial or final */\nexport type ExpoSpeechRecognitionResultEvent = {\n isFinal: boolean;\n results: ExpoSpeechRecognitionResult[];\n};\n\nexport type ExpoSpeechRecognitionErrorCode =\n /** The user called `ExpoSpeechRecognitionModule.abort()`. */\n | \"aborted\"\n /** Audio recording error. */\n | \"audio-capture\"\n /** There was an error in the speech recognition grammar or semantic tags, or the chosen grammar format or semantic tag format was unsupported. */\n | \"bad-grammar\"\n /** Locale is not supported by the speech recognizer. */\n | \"language-not-supported\"\n /** Network communication required for completing the recognition failed. */\n | \"network\"\n /** No final speech was detected. */\n | \"no-speech\"\n /** Permission to use speech recognition or microphone was not granted. */\n | \"not-allowed\"\n /** Recognizer is unavailable. */\n | \"service-not-allowed\"\n // Extra codes (not part of the spec)\n /** The recognizer is busy and cannot accept any new recognition requests. */\n | \"busy\"\n /** (Android only) An unknown client-side error occurred. */\n | \"client\"\n /** (Android) No speech input. */\n | \"speech-timeout\"\n /** (Android) Unknown error */\n | \"unknown\";\n\nexport type ExpoSpeechRecognitionErrorEvent = {\n error: ExpoSpeechRecognitionErrorCode;\n message: string;\n};\n\nexport type LanguageDetectionEvent = {\n /** The language that was detected, in BCP-47 format. e.g. \"en-US\", \"de-DE\" */\n detectedLanguage: string;\n /** The confidence of the detected language. A value ranging between 0.0 and 1.0.\n *\n * Values range from:\n *\n * - 1.0 (highly confident)\n * - 0.8 (confident)\n * - 0.5 (not confident)\n * - 0.0 (unknown)\n */\n confidence: number;\n /** The alternative locales for the same language, in BCP-47 format. e.g. [\"en-US\", \"en-GB\"] */\n topLocaleAlternatives: string[];\n};\n\n/**\n * Events that are dispatched from the native side\n */\nexport type ExpoSpeechRecognitionNativeEventMap = {\n result: ExpoSpeechRecognitionResultEvent;\n error: ExpoSpeechRecognitionErrorEvent;\n start: null;\n speechstart: null;\n speechend: null;\n /** A final result is returned with no significant recognition */\n nomatch: null;\n /** Audio capturing had started */\n audiostart: {\n /**\n * The uri is set when `recordingOptions.persist` is enabled.\n * Do not attempt to use this file until the `audioend` event is emitted.\n *\n * Example URIs:\n *\n * - Android: `file:///data/user/0/expo.modules.speechrecognition.example/cache/recording_1720678500903.wav`\n * - iOS: `file:///path/to/Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.caf`\n */\n uri: string | null;\n };\n /** Audio capturing had ended */\n audioend: {\n /**\n * The uri is set when `recordingOptions.persist` is enabled.\n *\n * Example URIs:\n *\n * - Android: `file:///data/user/0/expo.modules.speechrecognition.example/cache/recording_1720678500903.wav`\n * - iOS: `file:///path/to/Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.caf`\n */\n uri: string | null;\n };\n end: null;\n soundstart: null;\n soundend: null;\n languagedetection: LanguageDetectionEvent;\n volumechange: {\n /**\n * A float value between -2 and 10 indicating the volume of the input audio\n *\n * Consider anything below 0 to be inaudible\n */\n value: number;\n };\n};\n\nexport type ExpoSpeechRecognitionOptions = {\n /** [Default: \"en-US\"] The language of the speech recognition */\n lang?: string;\n /** [Default: false] Note for iOS: final results are only available after speech recognition has stopped */\n interimResults?: boolean;\n /** [Default: 5] The maximum number of alternative transcriptions to return. */\n maxAlternatives?: number;\n /**\n * An array of strings that will be used to provide context to the speech recognition engine.\n *\n * On Android, this configures [`EXTRA_BIASING_STRINGS`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_BIASING_STRINGS) in the recognizer intent (API level 33+).\n *\n * On iOS, this configures [`SFSpeechRecognitionRequest.contextualStrings`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/1649391-contextualstrings).\n */\n contextualStrings?: string[];\n /**\n * [Default: false] Continuous recognition.\n *\n * Not supported on Android 12 and below.\n *\n * If false, the behaviors are the following:\n *\n * - on iOS 17-, recognition will run until no speech is detected for 3 seconds.\n * - on iOS 18+ and Android, recognition will run until a result with `isFinal: true` is received.\n */\n continuous?: boolean;\n /** [Default: false] Prevent device from sending audio over the network. Only enabled if the device supports it.\n *\n * Use `getSupportedLocales()` to verify if the locale is installed on the device prior to enabling this option.\n */\n requiresOnDeviceRecognition?: boolean;\n /**\n * [Default: false] Include punctuation in the recognition results. This applies to full stops and commas.\n *\n * On Android, this configures [`EXTRA_ENABLE_FORMATTING`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING) in the recognizer intent (Android 13+, API level 33+).\n *\n * Note for Android: This feature is only verified to work on Android 13+ with on-device speech recognition enabled (i.e. enabling `requiresOnDeviceRecognition` or using the `com.google.android.as` service package)\n *\n * On iOS, this configures [`SFSpeechRecognitionRequest.addsPunctuation`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/3930023-addspunctuation).\n */\n addsPunctuation?: boolean;\n /**\n * The package name of the speech recognition service to use.\n * If not provided, the default service will be used.\n *\n * Obtain the supported packages by running `ExpoSpeechRecognitionModule.getSpeechRecognitionServices()`\n *\n * e.g. \"com.google.android.as\" or \"com.samsung.android.bixby.agent\"\n */\n androidRecognitionServicePackage?: string;\n /**\n * Extra options to provide to the Android Recognition intent.\n *\n * For a full list of options, see https://developer.android.com/reference/android/speech/RecognizerIntent\n */\n androidIntentOptions?: Partial<AndroidIntentOptions>;\n /**\n * Audio source options to pass to the recognizer.\n *\n * This option can be used to recognize audio from a local or remote file URI.\n */\n audioSource?: AudioSourceOptions;\n /**\n * Audio recording options for persisting the audio to a local file path.\n */\n recordingOptions?: RecordingOptions;\n /**\n * Default: `\"android.speech.action.RECOGNIZE_SPEECH\"`\n *\n * The kind of intent action\n *\n * Intents:\n *\n * - [`android.speech.action.RECOGNIZE_SPEECH`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_RECOGNIZE_SPEECH) which performs speech recognition (default)\n * - [`android.speech.action.VOICE_SEARCH_HANDS_FREE`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_VOICE_SEARCH_HANDS_FREE) - prompts the user for speech without requiring the user's visual attention or touch input\n * - [`android.speech.action.WEB_SEARCH`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_WEB_SEARCH) - displays a web search result or trigger another type of action based on the user's speech.\n */\n androidIntent?:\n | \"android.speech.action.RECOGNIZE_SPEECH\"\n | \"android.speech.action.VOICE_SEARCH_HANDS_FREE\"\n | \"android.speech.action.WEB_SEARCH\";\n\n /**\n * The hint for the speech recognition task.\n *\n * Default: `\"unspecified\"`\n *\n * Docs: https://developer.apple.com/documentation/speech/sfspeechrecognitiontaskhint\n */\n iosTaskHint?: IOSTaskHintValue;\n\n /**\n * The audio category for the speech recognition task.\n *\n * Use this option to configure the default audio session category and mode prior to starting speech recognition.\n *\n * **Caution:** confirm that the category, options and mode are compatible with the audio source.\n *\n * By default, the audio session category and mode are set to:\n *\n * - category: `playAndRecord`\n * - options: `defaultToSpeaker` and `allowBluetooth`\n * - mode: `measurement`\n *\n * Docs: https://developer.apple.com/documentation/avfaudio/avaudiosession/category\n */\n iosCategory?: SetCategoryOptions;\n\n /**\n * Settings for volume change events.\n */\n volumeChangeEventOptions?: {\n /**\n * Whether to emit volume change events.\n *\n * Default: false\n */\n enabled?: boolean;\n /**\n * Specifies the interval (in milliseconds) to emit `volumechange` events.\n *\n * Default: 100ms on iOS\n *\n * Increasing this value will improve performance\n */\n intervalMillis?: number;\n };\n};\n\nexport type IOSTaskHintValue = (typeof TaskHintIOS)[keyof typeof TaskHintIOS];\n\nexport type RecordingOptions = {\n /**\n * Whether to persist the audio to a local file path.\n *\n * Default: false\n */\n persist: boolean;\n /**\n * Default: `FileSystem.CacheDirectory`. This changes the default storage location for the audio file.\n */\n outputDirectory?: string;\n /**\n * Default: `\"recording_${timestamp|uuid}.[wav|caf]\"`. This changes the file name for the audio file.\n */\n outputFileName?: string;\n /**\n * Default: undefined. The sample rate of the output audio file.\n *\n * Only supported on iOS\n *\n * Default sample rate is: 16000 on Android, 44100/48000 on iOS\n */\n outputSampleRate?: number;\n /**\n * Default: undefined. The encoding of the output audio file.\n *\n * Only supported on iOS\n */\n outputEncoding?:\n | \"pcmFormatFloat32\"\n | \"pcmFormatFloat64\"\n | \"pcmFormatInt16\"\n | \"pcmFormatInt32\";\n};\n\nexport type AudioSourceOptions = {\n /**\n * Local audio source URI.\n *\n * e.g. `\"file:///storage/emulated/0/Download/audio.wav\"`\n */\n uri: string;\n /**\n * [Android only] The number of channels in the source audio.\n *\n * Default: 1\n */\n audioChannels?: number;\n /**\n * [Android only] A value from [AudioFormat](https://developer.android.com/reference/android/media/AudioFormat).\n *\n * Use the `AudioEncodingAndroid` enum to get the correct value.\n */\n audioEncoding?: AudioEncodingAndroidValue;\n /**\n * [Android only] Audio sampling rate in Hz.\n *\n * Default: 16000\n */\n sampleRate?: number;\n /**\n * [Android only] The delay for a 4KiB chunk of audio to stream to the speech recognition service.\n *\n * Use this setting to avoid being rate-limited when using network-based recognition.\n *\n * If you're using on-device recognition, you may want to increase this value to avoid unprocessed audio chunks.\n *\n * Default: 50ms for network-based recognition, 15ms for on-device recognition\n */\n chunkDelayMillis?: number;\n};\n\nexport type AudioEncodingAndroidValue =\n (typeof AudioEncodingAndroid)[keyof typeof AudioEncodingAndroid];\n\nexport type AndroidIntentOptions = {\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_CALLING_PACKAGE\n *\n * The extra key used in an intent to the speech recognizer for voice search. Not generally to be used by developers. The system search dialog uses this, for example, to set a calling package for identification by a voice search API. If this extra is set by anyone but the system process, it should be overridden by the voice search implementation.\n */\n EXTRA_CALLING_PACKAGE: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_BIASING_DEVICE_CONTEXT\n *\n * Optional boolean to enable biasing towards device context. The recognizer will use the device context to tune the recognition results.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_ENABLE_BIASING_DEVICE_CONTEXT: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_LANGUAGE_DETECTION\n *\n * Optional boolean indicating whether to enable language detection. When enabled, the recognizer will consistently identify the language of the current spoken utterance and provide that info via RecognitionListener#onLanguageDetection(Bundle).\n */\n EXTRA_ENABLE_LANGUAGE_DETECTION: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_LANGUAGE_SWITCH\n *\n * Optional string to enable automatic switching to the language being spoken with the desired sensitivity level, instead of being restricted to a single language. The corresponding language models must be downloaded to support the switch. Otherwise, the recognizer will report an error on a switch failure. The recognizer provides the switch results via RecognitionListener#onLanguageDetection(Bundle).\n *\n * Since detection is a necessary requirement for the language switching, setting this value implicitly enables EXTRA_ENABLE_LANGUAGE_DETECTION.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_ENABLE_LANGUAGE_SWITCH: (typeof RecognizerIntentEnableLanguageSwitch)[keyof typeof RecognizerIntentEnableLanguageSwitch];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING\n *\n * NOTE: This is also configurable through `addsPunctuation` (which sets `EXTRA_ENABLE_FORMATTING` to \"quality\")\n *\n * [API level 33] Optional string to enable text formatting (e.g. unspoken punctuation (examples: question mark, comma, period, etc.), capitalization, etc.) and specify the optimization strategy. If set, the partial and final result texts will be formatted. Each result list will contain two hypotheses in the order of 1) formatted text 2) raw text.\n *\n */\n EXTRA_ENABLE_FORMATTING: \"latency\" | \"quality\";\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION\n *\n * [API level 33] Optional boolean, to be used with EXTRA_ENABLE_FORMATTING, to prevent the recognizer adding punctuation after the last word of the partial results. The default is false.\n */\n EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION: boolean;\n /**\n * Optional list of IETF language tags (as defined by BCP 47, e.g. \"en-US\", \"de-DE\").\n *\n * [API level 34] This extra is to be used with EXTRA_ENABLE_LANGUAGE_DETECTION. If set, the recognizer will constrain the language detection output to this list of languages, potentially improving detection accuracy.\n */\n EXTRA_LANGUAGE_DETECTION_ALLOWED_LANGUAGES: string[];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_MODEL\n *\n * [Default: free_form] The language model to use for speech recognition.\n *\n * Informs the recognizer which speech model to prefer when performing ACTION_RECOGNIZE_SPEECH.\n * The recognizer uses this information to fine tune the results.\n * This extra is required. Activities implementing ACTION_RECOGNIZE_SPEECH may interpret the values as they see fit.\n */\n EXTRA_LANGUAGE_MODEL: (typeof RecognizerIntentExtraLanguageModel)[keyof typeof RecognizerIntentExtraLanguageModel];\n\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_ALLOWED_LANGUAGES\n *\n * [API level 34] Optional list of IETF language tags (as defined by BCP 47, e.g. \"en-US\", \"de-DE\").\n * This extra is to be used with EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the recognizer will apply the auto switch only to these languages, even if the speech models of other languages also exist.\n * The corresponding language models must be downloaded to support the switch. Otherwise, the recognizer will report an error on a switch failure.\n */\n EXTRA_LANGUAGE_SWITCH_ALLOWED_LANGUAGES: string[];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS\n *\n * [API level 35] Optional integer to use for EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the language switch will only be activated for this value of ms of audio since the START_OF_SPEECH. This could provide a more stable recognition result when the language switch is only required in the beginning of the session.\n */\n EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_MAX_SWITCHES\n *\n * [API level 35] Optional integer to use for EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the language switch will be deactivated when LANGUAGE_SWITCH_MAX_SWITCHES reached.\n *\n * Depending on the recognizer implementation, this flag may have no effect.\n */\n EXTRA_LANGUAGE_SWITCH_MAX_SWITCHES: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_MASK_OFFENSIVE_WORDS\n *\n * [API level 33] Optional boolean indicating whether the recognizer should mask the offensive words in recognition results. The Default is true.\n *\n * Constant Value: \"android.speech.extra.MASK_OFFENSIVE_WORDS\"\n */\n EXTRA_MASK_OFFENSIVE_WORDS: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ORIGIN\n *\n * Optional value which can be used to indicate the referer url of a page in which speech was requested. For example, a web browser may choose to provide this for uses of speech on a given page.\n */\n EXTRA_ORIGIN: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_PREFER_OFFLINE\n *\n * Optional boolean, to be used with ACTION_RECOGNIZE_SPEECH, ACTION_VOICE_SEARCH_HANDS_FREE, ACTION_WEB_SEARCH to indicate whether to only use an offline speech recognition engine. The default is false, meaning that either network or offline recognition engines may be used.\n *\n * Depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_PREFER_OFFLINE: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_PROMPT\n *\n * Optional text prompt to show to the user when asking them to speak.\n */\n EXTRA_PROMPT: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_REQUEST_WORD_CONFIDENCE\n *\n * [API level 34] Optional boolean indicating whether the recognizer should return the confidence level of each word in the final recognition results.\n */\n EXTRA_REQUEST_WORD_CONFIDENCE: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_REQUEST_WORD_TIMING\n *\n * [API level 34] Optional boolean indicating whether the recognizer should return the timestamp of each word in the final recognition results.\n */\n EXTRA_REQUEST_WORD_TIMING: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SECURE\n *\n * Optional boolean to indicate that a \"hands free\" voice search was performed while the device was in a secure mode. An example of secure mode is when the device's screen lock is active, and it requires some form of authentication to be unlocked. When the device is securely locked, the voice search activity should either restrict the set of voice actions that are permitted, or require some form of secure authentication before proceeding.\n */\n EXTRA_SECURE: boolean;\n /**\n * Optional string to enable segmented session mode of the specified type,\n * which can be `EXTRA_AUDIO_SOURCE`, `EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS` or `EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS`.\n * When segmented session mode is supported by the recognizer implementation and this extra is set,\n * it will return the recognition results in segments via [RecognitionListener#onSegmentResults(Bundle)](https://developer.android.com/reference/android/speech/RecognitionListener#onSegmentResults(android.os.Bundle))\n * and terminate the session with [RecognitionListener#onEndOfSegmentedSession()](https://developer.android.com/reference/android/speech/RecognitionListener#onEndOfSegmentedSession()).\n *\n * When setting this extra, make sure the extra used as the string value here is also set in the same intent with proper value.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_SEGMENTED_SESSION:\n | \"android.speech.extra.AUDIO_SOURCE\"\n | \"android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS\"\n | \"android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS\";\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS\n *\n * The amount of time that it should take after the recognizer stops hearing speech to consider the input complete hence end the recognition session.\n *\n * Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!\n *\n * Depending on the recognizer implementation, these values may have no effect.\n *\n */\n EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS\n *\n * Optional integer to indicate the minimum length of the recognition session. The recognizer will not stop recognizing speech before this amount of time.\n *\n * Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!\n *\n * Depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS\n *\n * The amount of time that it should take after we stop hearing speech to consider the input possibly complete.\n * This is used to prevent the endpointer cutting off during very short mid-speech pauses.\n * Note that it is extremely rare you'd want to specify this value in an intent.\n * If you don't have a very good reason to change these, you should leave them as they are.\n * Note also that certain values may cause undesired or unexpected results - use judiciously!\n * Additionally, depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS: number;\n};\n\nexport type ExpoSpeechRecognitionNativeEvents = {\n [K in keyof ExpoSpeechRecognitionNativeEventMap]: (\n event: ExpoSpeechRecognitionNativeEventMap[K],\n ) => void;\n};\n\nexport declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSpeechRecognitionNativeEvents> {\n /**\n * Starts speech recognition.\n */\n start(options: ExpoSpeechRecognitionOptions): void;\n /**\n * Stops speech recognition and attempts to return a final result (through the `result` event).\n */\n stop(): void;\n /**\n * Cancels speech recognition immediately without returning a final result.\n */\n abort(): void;\n /**\n * Presents a dialog to the user to request permissions for using speech recognition and the microphone.\n *\n * For Android, this will request RECORD_AUDIO permission.\n *\n * For iOS, this will request microphone and speech recognition permissions.\n * Once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestPermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Returns the current permission status for speech recognition and the microphone.\n *\n * You may also use `getMicrophonePermissionsAsync` and `getSpeechRecognizerPermissionsAsync` to get the permissions separately.\n */\n getPermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Returns the current permission status for the microphone.\n */\n getMicrophonePermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Presents a dialog to the user to request permissions for using the microphone.\n *\n * For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestMicrophonePermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Returns the current permission status for speech recognition.\n */\n getSpeechRecognizerPermissionsAsync(): Promise<PermissionResponse>;\n /**\n * [iOS only] Presents a dialog to the user to request permissions for using the speech recognizer.\n * This permission is required when `requiresOnDeviceRecognition` is disabled (i.e. network-based recognition)\n *\n * For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestSpeechRecognizerPermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Returns an array of locales supported by the speech recognizer.\n *\n * Not supported on Android 12 and below (API level 31), this will return an empty array of locales.\n *\n * @throws {\"package_not_found\"} If the service package is not found.\n * @throws {\"error_[number]\"} If there was an error retrieving the supported locales.\n */\n getSupportedLocales(options: {\n /**\n * The package name of the speech recognition service to use.\n *\n * e.g. \"com.google.android.as\" or \"com.samsung.android.bixby.agent\"\n *\n * Warning: the service package (such as Bixby) may not be able to return any results.\n */\n androidRecognitionServicePackage?: string;\n }): Promise<{\n /**\n * All supported languages on the device. This includes both installed and supported languages.\n */\n locales: string[];\n /**\n * These languages are installed on to the device for offline use.\n *\n * This will likely be an empty array if the service package is not \"com.google.android.as\"\n */\n installedLocales: string[];\n }>;\n /**\n * [Android only] Returns an array of package names of speech recognition services that are available on the device.\n *\n * List of all available services as bundle identifiers, e.g. [\"com.google.android.as\", \"com.google.android.tts\"]\n */\n getSpeechRecognitionServices(): string[];\n /**\n * [Android only] Returns the default voice recognition service on the device.\n *\n * @returns empty string if no service is found, or not Android\n */\n getDefaultRecognitionService(): {\n /** e.g. \"com.google.android.tts\" or \"com.google.android.googlequicksearchbox\" */\n packageName: string;\n };\n /**\n * [Android only] Returns the default voice recognition service on the device.\n *\n * e.g. \"com.google.android.googlequicksearchbox\" or \"com.samsung.android.bixby.agent\"\n *\n * @returns empty string if no service is found, or not Android\n */\n getAssistantService(): {\n /** e.g. \"com.google.android.googlequicksearchbox\" or \"com.samsung.android.bixby.agent\" */\n packageName: string;\n };\n /**\n * Whether the on-device speech recognition is available on the device.\n */\n supportsOnDeviceRecognition(): boolean;\n /**\n * Whether the recording feature is available on the device.\n *\n * This mostly applies to Android devices, to check if it's greater than Android 13.\n */\n supportsRecording(): boolean;\n /**\n * Whether on-device speech recognition is available.\n *\n * If this method returns false, `start()` will fail and emit an error event with the code `service-not-allowed` or `language-not-supported`.\n */\n isRecognitionAvailable(): boolean;\n\n /**\n * Downloads the offline model for the specified locale.\n * Note: this is only supported on Android 13 and above.\n */\n androidTriggerOfflineModelDownload(options: {\n /** The locale to download the model for, e.g. \"en-US\" */\n locale: string;\n }): Promise<{\n /**\n * On Android 13, the status will be \"opened_dialog\" indicating that the model download dialog was opened.\n * On Android 14+, the status will be \"download_success\" indicating that the model download was successful.\n * On Android 14+, \"download_canceled\" will be returned if the download was canceled by a user interaction.\n */\n status: \"download_success\" | \"opened_dialog\" | \"download_canceled\";\n message: string;\n }>;\n /**\n * [iOS only] For advanced use cases, you may use this function to set the audio session category and mode.\n *\n * See: https://developer.apple.com/documentation/avfaudio/avaudiosession/1771734-setcategory\n */\n setCategoryIOS(options: SetCategoryOptions): void;\n\n /**\n * [iOS only] Returns the current audio session category and options.\n *\n * See:\n * - [AVAudioSession.Category](https://developer.apple.com/documentation/avfaudio/avaudiosession/category)\n * - [AVAudioSession.CategoryOptions](https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions)\n * - [AVAudioSession.Mode](https://developer.apple.com/documentation/avfaudio/avaudiosession/mode)\n */\n getAudioSessionCategoryAndOptionsIOS(): {\n category: AVAudioSessionCategoryValue;\n categoryOptions: AVAudioSessionCategoryOptionsValue[];\n mode: AVAudioSessionModeValue;\n };\n /**\n * [iOS only] Sets the shared audio session active state.\n *\n * Calls the following on iOS: `AVAudioSession.sharedInstance().setActive(value, options)`\n *\n * See: https://developer.apple.com/documentation/avfaudio/avaudiosession/1616627-setactive\n */\n setAudioSessionActiveIOS(\n value: boolean,\n options?: {\n /** [Default: true] Whether to notify other audio sessions when the active state changes. */\n notifyOthersOnDeactivation: boolean;\n },\n ): void;\n /**\n * Returns the current state of the speech recognizer.\n */\n getStateAsync(): Promise<SpeechRecognitionState>;\n}\n\nexport type SetCategoryOptions = {\n category: AVAudioSessionCategoryValue;\n categoryOptions: AVAudioSessionCategoryOptionsValue[];\n mode?: AVAudioSessionModeValue;\n};\n\ntype SpeechRecognitionState =\n | \"inactive\"\n | \"starting\"\n | \"recognizing\"\n | \"stopping\";\n\n/**\n * [iOS only] See: [AVAudioSession.CategoryOptions](https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions)\n *\n * Use the `AVAudioSessionCategoryOptions` enum to get the correct value.\n */\nexport type AVAudioSessionCategoryOptionsValue =\n (typeof AVAudioSessionCategoryOptions)[keyof typeof AVAudioSessionCategoryOptions];\n\n/**\n * [iOS only] See: [AVAudioSession.Mode](https://developer.apple.com/documentation/avfaudio/avaudiosession/mode)\n *\n * Use the `AVAudioSessionMode` enum to get the correct value.\n */\nexport type AVAudioSessionModeValue =\n (typeof AVAudioSessionMode)[keyof typeof AVAudioSessionMode];\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoSpeechRecognitionModule.types.js","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { PermissionResponse } from \"expo-modules-core\";\nimport type { NativeModule } from \"expo\";\n\nexport type ExpoSpeechRecognitionPermissionResponse = PermissionResponse & {\n /**\n * Whether the speech recognition is restricted by Content & Privacy Restrictions.\n *\n * This value corresponds to the `restricted` enum of `SFSpeechRecognizer.authorizationStatus()`.\n *\n * This is only available on iOS.\n */\n restricted?: boolean;\n};\n\nimport type {\n AudioEncodingAndroid,\n AVAudioSessionCategory,\n AVAudioSessionCategoryOptions,\n AVAudioSessionMode,\n RecognizerIntentEnableLanguageSwitch,\n RecognizerIntentExtraLanguageModel,\n TaskHintIOS,\n} from \"./constants\";\n\nexport type AVAudioSessionCategoryValue =\n (typeof AVAudioSessionCategory)[keyof typeof AVAudioSessionCategory];\n\nexport type ExpoSpeechRecognitionResult = {\n transcript: string;\n /**\n * Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating transcript confidence.\n */\n confidence: number;\n /**\n * An array of transcription segments that represent the parts of the transcription, as identified by the speech recognizer.\n *\n * Notes for Android:\n *\n * - This is only available for SDK 34+ (Android 14+)\n * - This is only verified to work with the `com.google.android.as` service (using on device speech recognition)\n * - Segments are only available during the final result\n * - The segment parts are split up by words.\n * - The segments are only available for the first transcript\n * - Segment confidences currently return as -1 (unavailable)\n *\n * Notes for iOS:\n *\n * - The confidence value will be 0 on partial results\n */\n segments: ExpoSpeechRecognitionResultSegment[];\n};\n\nexport type ExpoSpeechRecognitionResultSegment = {\n /** The start timestamp of the utterance, e.g. 1000 */\n startTimeMillis: number;\n /** The end timestamp of the utterance, e.g. 1500 */\n endTimeMillis: number;\n /** The text portion of the transcript, e.g. \"Hello world\" */\n segment: string;\n /** Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating the confidence of the specific segment */\n confidence: number;\n};\n\n/** Fired when there's a speech result. The result may be partial or final */\nexport type ExpoSpeechRecognitionResultEvent = {\n isFinal: boolean;\n results: ExpoSpeechRecognitionResult[];\n};\n\nexport type ExpoSpeechRecognitionErrorCode =\n /** The user called `ExpoSpeechRecognitionModule.abort()`. */\n | \"aborted\"\n /** Audio recording error. */\n | \"audio-capture\"\n /** There was an error in the speech recognition grammar or semantic tags, or the chosen grammar format or semantic tag format was unsupported. */\n | \"bad-grammar\"\n /** Locale is not supported by the speech recognizer. */\n | \"language-not-supported\"\n /** Network communication required for completing the recognition failed. */\n | \"network\"\n /** No final speech was detected. */\n | \"no-speech\"\n /** Permission to use speech recognition or microphone was not granted. */\n | \"not-allowed\"\n /** Recognizer is unavailable. */\n | \"service-not-allowed\"\n // Extra codes (not part of the spec)\n /** The recognizer is busy and cannot accept any new recognition requests. */\n | \"busy\"\n /** (Android only) An unknown client-side error occurred. */\n | \"client\"\n /** (Android) No speech input. */\n | \"speech-timeout\"\n /** (Android) Unknown error */\n | \"unknown\";\n\nexport type ExpoSpeechRecognitionErrorEvent = {\n error: ExpoSpeechRecognitionErrorCode;\n message: string;\n};\n\nexport type LanguageDetectionEvent = {\n /** The language that was detected, in BCP-47 format. e.g. \"en-US\", \"de-DE\" */\n detectedLanguage: string;\n /** The confidence of the detected language. A value ranging between 0.0 and 1.0.\n *\n * Values range from:\n *\n * - 1.0 (highly confident)\n * - 0.8 (confident)\n * - 0.5 (not confident)\n * - 0.0 (unknown)\n */\n confidence: number;\n /** The alternative locales for the same language, in BCP-47 format. e.g. [\"en-US\", \"en-GB\"] */\n topLocaleAlternatives: string[];\n};\n\n/**\n * Events that are dispatched from the native side\n */\nexport type ExpoSpeechRecognitionNativeEventMap = {\n result: ExpoSpeechRecognitionResultEvent;\n error: ExpoSpeechRecognitionErrorEvent;\n start: null;\n speechstart: null;\n speechend: null;\n /** A final result is returned with no significant recognition */\n nomatch: null;\n /** Audio capturing had started */\n audiostart: {\n /**\n * The uri is set when `recordingOptions.persist` is enabled.\n * Do not attempt to use this file until the `audioend` event is emitted.\n *\n * Example URIs:\n *\n * - Android: `file:///data/user/0/expo.modules.speechrecognition.example/cache/recording_1720678500903.wav`\n * - iOS: `file:///path/to/Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.caf`\n */\n uri: string | null;\n };\n /** Audio capturing had ended */\n audioend: {\n /**\n * The uri is set when `recordingOptions.persist` is enabled.\n *\n * Example URIs:\n *\n * - Android: `file:///data/user/0/expo.modules.speechrecognition.example/cache/recording_1720678500903.wav`\n * - iOS: `file:///path/to/Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.caf`\n */\n uri: string | null;\n };\n end: null;\n soundstart: null;\n soundend: null;\n languagedetection: LanguageDetectionEvent;\n volumechange: {\n /**\n * A float value between -2 and 10 indicating the volume of the input audio\n *\n * Consider anything below 0 to be inaudible\n */\n value: number;\n };\n};\n\nexport type ExpoSpeechRecognitionOptions = {\n /** [Default: \"en-US\"] The language of the speech recognition */\n lang?: string;\n /** [Default: false] Note for iOS: final results are only available after speech recognition has stopped */\n interimResults?: boolean;\n /** [Default: 5] The maximum number of alternative transcriptions to return. */\n maxAlternatives?: number;\n /**\n * An array of strings that will be used to provide context to the speech recognition engine.\n *\n * On Android, this configures [`EXTRA_BIASING_STRINGS`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_BIASING_STRINGS) in the recognizer intent (API level 33+).\n *\n * On iOS, this configures [`SFSpeechRecognitionRequest.contextualStrings`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/1649391-contextualstrings).\n */\n contextualStrings?: string[];\n /**\n * [Default: false] Continuous recognition.\n *\n * Not supported on Android 12 and below.\n *\n * If false, the behaviors are the following:\n *\n * - on iOS 17-, recognition will run until no speech is detected for 3 seconds.\n * - on iOS 18+ and Android, recognition will run until a result with `isFinal: true` is received.\n */\n continuous?: boolean;\n /** [Default: false] Prevent device from sending audio over the network. Only enabled if the device supports it.\n *\n * Use `getSupportedLocales()` to verify if the locale is installed on the device prior to enabling this option.\n */\n requiresOnDeviceRecognition?: boolean;\n /**\n * [Default: false] Include punctuation in the recognition results. This applies to full stops and commas.\n *\n * On Android, this configures [`EXTRA_ENABLE_FORMATTING`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING) in the recognizer intent (Android 13+, API level 33+).\n *\n * Note for Android: This feature is only verified to work on Android 13+ with on-device speech recognition enabled (i.e. enabling `requiresOnDeviceRecognition` or using the `com.google.android.as` service package)\n *\n * On iOS, this configures [`SFSpeechRecognitionRequest.addsPunctuation`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/3930023-addspunctuation).\n */\n addsPunctuation?: boolean;\n /**\n * The package name of the speech recognition service to use.\n * If not provided, the default service will be used.\n *\n * Obtain the supported packages by running `ExpoSpeechRecognitionModule.getSpeechRecognitionServices()`\n *\n * e.g. \"com.google.android.as\" or \"com.samsung.android.bixby.agent\"\n */\n androidRecognitionServicePackage?: string;\n /**\n * Extra options to provide to the Android Recognition intent.\n *\n * For a full list of options, see https://developer.android.com/reference/android/speech/RecognizerIntent\n */\n androidIntentOptions?: Partial<AndroidIntentOptions>;\n /**\n * Audio source options to pass to the recognizer.\n *\n * This option can be used to recognize audio from a local or remote file URI.\n */\n audioSource?: AudioSourceOptions;\n /**\n * Audio recording options for persisting the audio to a local file path.\n */\n recordingOptions?: RecordingOptions;\n /**\n * Default: `\"android.speech.action.RECOGNIZE_SPEECH\"`\n *\n * The kind of intent action\n *\n * Intents:\n *\n * - [`android.speech.action.RECOGNIZE_SPEECH`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_RECOGNIZE_SPEECH) which performs speech recognition (default)\n * - [`android.speech.action.VOICE_SEARCH_HANDS_FREE`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_VOICE_SEARCH_HANDS_FREE) - prompts the user for speech without requiring the user's visual attention or touch input\n * - [`android.speech.action.WEB_SEARCH`](https://developer.android.com/reference/android/speech/RecognizerIntent#ACTION_WEB_SEARCH) - displays a web search result or trigger another type of action based on the user's speech.\n */\n androidIntent?:\n | \"android.speech.action.RECOGNIZE_SPEECH\"\n | \"android.speech.action.VOICE_SEARCH_HANDS_FREE\"\n | \"android.speech.action.WEB_SEARCH\";\n\n /**\n * The hint for the speech recognition task.\n *\n * Default: `\"unspecified\"`\n *\n * Docs: https://developer.apple.com/documentation/speech/sfspeechrecognitiontaskhint\n */\n iosTaskHint?: IOSTaskHintValue;\n\n /**\n * The audio category for the speech recognition task.\n *\n * Use this option to configure the default audio session category and mode prior to starting speech recognition.\n *\n * **Caution:** confirm that the category, options and mode are compatible with the audio source.\n *\n * By default, the audio session category and mode are set to:\n *\n * - category: `playAndRecord`\n * - options: `defaultToSpeaker` and `allowBluetooth`\n * - mode: `measurement`\n *\n * Docs: https://developer.apple.com/documentation/avfaudio/avaudiosession/category\n */\n iosCategory?: SetCategoryOptions;\n\n /**\n * Settings for volume change events.\n */\n volumeChangeEventOptions?: {\n /**\n * Whether to emit volume change events.\n *\n * Default: false\n */\n enabled?: boolean;\n /**\n * Specifies the interval (in milliseconds) to emit `volumechange` events.\n *\n * Default: 100ms on iOS\n *\n * Increasing this value will improve performance\n */\n intervalMillis?: number;\n };\n\n /**\n * [iOS only] Enabling this option will prevent microphone feedback.\n *\n * When enabled, extra signal processing is applied on the incoming audio, and any audio that is coming from the device is taken out.\n *\n * (This option will place both input and output nodes in voice processing mode as noted in Apple docs: http://developer.apple.com/videos/play/wwdc2019/510/?time=66)\n */\n iosVoiceProcessingEnabled?: boolean;\n};\n\nexport type IOSTaskHintValue = (typeof TaskHintIOS)[keyof typeof TaskHintIOS];\n\nexport type RecordingOptions = {\n /**\n * Whether to persist the audio to a local file path.\n *\n * Default: false\n */\n persist: boolean;\n /**\n * Default: `FileSystem.CacheDirectory`. This changes the default storage location for the audio file.\n */\n outputDirectory?: string;\n /**\n * Default: `\"recording_${timestamp|uuid}.[wav|caf]\"`. This changes the file name for the audio file.\n */\n outputFileName?: string;\n /**\n * Default: undefined. The sample rate of the output audio file.\n *\n * Only supported on iOS\n *\n * Default sample rate is: 16000 on Android, 44100/48000 on iOS\n */\n outputSampleRate?: number;\n /**\n * Default: undefined. The encoding of the output audio file.\n *\n * Only supported on iOS\n */\n outputEncoding?:\n | \"pcmFormatFloat32\"\n | \"pcmFormatFloat64\"\n | \"pcmFormatInt16\"\n | \"pcmFormatInt32\";\n};\n\nexport type AudioSourceOptions = {\n /**\n * Local audio source URI.\n *\n * e.g. `\"file:///storage/emulated/0/Download/audio.wav\"`\n */\n uri: string;\n /**\n * [Android only] The number of channels in the source audio.\n *\n * Default: 1\n */\n audioChannels?: number;\n /**\n * [Android only] A value from [AudioFormat](https://developer.android.com/reference/android/media/AudioFormat).\n *\n * Use the `AudioEncodingAndroid` enum to get the correct value.\n */\n audioEncoding?: AudioEncodingAndroidValue;\n /**\n * [Android only] Audio sampling rate in Hz.\n *\n * Default: 16000\n */\n sampleRate?: number;\n /**\n * [Android only] The delay for a 4KiB chunk of audio to stream to the speech recognition service.\n *\n * Use this setting to avoid being rate-limited when using network-based recognition.\n *\n * If you're using on-device recognition, you may want to increase this value to avoid unprocessed audio chunks.\n *\n * Default: 50ms for network-based recognition, 15ms for on-device recognition\n */\n chunkDelayMillis?: number;\n};\n\nexport type AudioEncodingAndroidValue =\n (typeof AudioEncodingAndroid)[keyof typeof AudioEncodingAndroid];\n\nexport type AndroidIntentOptions = {\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_CALLING_PACKAGE\n *\n * The extra key used in an intent to the speech recognizer for voice search. Not generally to be used by developers. The system search dialog uses this, for example, to set a calling package for identification by a voice search API. If this extra is set by anyone but the system process, it should be overridden by the voice search implementation.\n */\n EXTRA_CALLING_PACKAGE: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_BIASING_DEVICE_CONTEXT\n *\n * Optional boolean to enable biasing towards device context. The recognizer will use the device context to tune the recognition results.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_ENABLE_BIASING_DEVICE_CONTEXT: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_LANGUAGE_DETECTION\n *\n * Optional boolean indicating whether to enable language detection. When enabled, the recognizer will consistently identify the language of the current spoken utterance and provide that info via RecognitionListener#onLanguageDetection(Bundle).\n */\n EXTRA_ENABLE_LANGUAGE_DETECTION: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_LANGUAGE_SWITCH\n *\n * Optional string to enable automatic switching to the language being spoken with the desired sensitivity level, instead of being restricted to a single language. The corresponding language models must be downloaded to support the switch. Otherwise, the recognizer will report an error on a switch failure. The recognizer provides the switch results via RecognitionListener#onLanguageDetection(Bundle).\n *\n * Since detection is a necessary requirement for the language switching, setting this value implicitly enables EXTRA_ENABLE_LANGUAGE_DETECTION.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_ENABLE_LANGUAGE_SWITCH: (typeof RecognizerIntentEnableLanguageSwitch)[keyof typeof RecognizerIntentEnableLanguageSwitch];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING\n *\n * NOTE: This is also configurable through `addsPunctuation` (which sets `EXTRA_ENABLE_FORMATTING` to \"quality\")\n *\n * [API level 33] Optional string to enable text formatting (e.g. unspoken punctuation (examples: question mark, comma, period, etc.), capitalization, etc.) and specify the optimization strategy. If set, the partial and final result texts will be formatted. Each result list will contain two hypotheses in the order of 1) formatted text 2) raw text.\n *\n */\n EXTRA_ENABLE_FORMATTING: \"latency\" | \"quality\";\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION\n *\n * [API level 33] Optional boolean, to be used with EXTRA_ENABLE_FORMATTING, to prevent the recognizer adding punctuation after the last word of the partial results. The default is false.\n */\n EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION: boolean;\n /**\n * Optional list of IETF language tags (as defined by BCP 47, e.g. \"en-US\", \"de-DE\").\n *\n * [API level 34] This extra is to be used with EXTRA_ENABLE_LANGUAGE_DETECTION. If set, the recognizer will constrain the language detection output to this list of languages, potentially improving detection accuracy.\n */\n EXTRA_LANGUAGE_DETECTION_ALLOWED_LANGUAGES: string[];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_MODEL\n *\n * [Default: free_form] The language model to use for speech recognition.\n *\n * Informs the recognizer which speech model to prefer when performing ACTION_RECOGNIZE_SPEECH.\n * The recognizer uses this information to fine tune the results.\n * This extra is required. Activities implementing ACTION_RECOGNIZE_SPEECH may interpret the values as they see fit.\n */\n EXTRA_LANGUAGE_MODEL: (typeof RecognizerIntentExtraLanguageModel)[keyof typeof RecognizerIntentExtraLanguageModel];\n\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_ALLOWED_LANGUAGES\n *\n * [API level 34] Optional list of IETF language tags (as defined by BCP 47, e.g. \"en-US\", \"de-DE\").\n * This extra is to be used with EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the recognizer will apply the auto switch only to these languages, even if the speech models of other languages also exist.\n * The corresponding language models must be downloaded to support the switch. Otherwise, the recognizer will report an error on a switch failure.\n */\n EXTRA_LANGUAGE_SWITCH_ALLOWED_LANGUAGES: string[];\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS\n *\n * [API level 35] Optional integer to use for EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the language switch will only be activated for this value of ms of audio since the START_OF_SPEECH. This could provide a more stable recognition result when the language switch is only required in the beginning of the session.\n */\n EXTRA_LANGUAGE_SWITCH_INITIAL_ACTIVE_DURATION_TIME_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_LANGUAGE_SWITCH_MAX_SWITCHES\n *\n * [API level 35] Optional integer to use for EXTRA_ENABLE_LANGUAGE_SWITCH. If set, the language switch will be deactivated when LANGUAGE_SWITCH_MAX_SWITCHES reached.\n *\n * Depending on the recognizer implementation, this flag may have no effect.\n */\n EXTRA_LANGUAGE_SWITCH_MAX_SWITCHES: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_MASK_OFFENSIVE_WORDS\n *\n * [API level 33] Optional boolean indicating whether the recognizer should mask the offensive words in recognition results. The Default is true.\n *\n * Constant Value: \"android.speech.extra.MASK_OFFENSIVE_WORDS\"\n */\n EXTRA_MASK_OFFENSIVE_WORDS: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ORIGIN\n *\n * Optional value which can be used to indicate the referer url of a page in which speech was requested. For example, a web browser may choose to provide this for uses of speech on a given page.\n */\n EXTRA_ORIGIN: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_PREFER_OFFLINE\n *\n * Optional boolean, to be used with ACTION_RECOGNIZE_SPEECH, ACTION_VOICE_SEARCH_HANDS_FREE, ACTION_WEB_SEARCH to indicate whether to only use an offline speech recognition engine. The default is false, meaning that either network or offline recognition engines may be used.\n *\n * Depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_PREFER_OFFLINE: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_PROMPT\n *\n * Optional text prompt to show to the user when asking them to speak.\n */\n EXTRA_PROMPT: string;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_REQUEST_WORD_CONFIDENCE\n *\n * [API level 34] Optional boolean indicating whether the recognizer should return the confidence level of each word in the final recognition results.\n */\n EXTRA_REQUEST_WORD_CONFIDENCE: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_REQUEST_WORD_TIMING\n *\n * [API level 34] Optional boolean indicating whether the recognizer should return the timestamp of each word in the final recognition results.\n */\n EXTRA_REQUEST_WORD_TIMING: boolean;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SECURE\n *\n * Optional boolean to indicate that a \"hands free\" voice search was performed while the device was in a secure mode. An example of secure mode is when the device's screen lock is active, and it requires some form of authentication to be unlocked. When the device is securely locked, the voice search activity should either restrict the set of voice actions that are permitted, or require some form of secure authentication before proceeding.\n */\n EXTRA_SECURE: boolean;\n /**\n * Optional string to enable segmented session mode of the specified type,\n * which can be `EXTRA_AUDIO_SOURCE`, `EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS` or `EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS`.\n * When segmented session mode is supported by the recognizer implementation and this extra is set,\n * it will return the recognition results in segments via [RecognitionListener#onSegmentResults(Bundle)](https://developer.android.com/reference/android/speech/RecognitionListener#onSegmentResults(android.os.Bundle))\n * and terminate the session with [RecognitionListener#onEndOfSegmentedSession()](https://developer.android.com/reference/android/speech/RecognitionListener#onEndOfSegmentedSession()).\n *\n * When setting this extra, make sure the extra used as the string value here is also set in the same intent with proper value.\n *\n * Depending on the recognizer implementation, this value may have no effect.\n */\n EXTRA_SEGMENTED_SESSION:\n | \"android.speech.extra.AUDIO_SOURCE\"\n | \"android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS\"\n | \"android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS\";\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS\n *\n * The amount of time that it should take after the recognizer stops hearing speech to consider the input complete hence end the recognition session.\n *\n * Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!\n *\n * Depending on the recognizer implementation, these values may have no effect.\n *\n */\n EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS\n *\n * Optional integer to indicate the minimum length of the recognition session. The recognizer will not stop recognizing speech before this amount of time.\n *\n * Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!\n *\n * Depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS: number;\n /**\n * https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS\n *\n * The amount of time that it should take after we stop hearing speech to consider the input possibly complete.\n * This is used to prevent the endpointer cutting off during very short mid-speech pauses.\n * Note that it is extremely rare you'd want to specify this value in an intent.\n * If you don't have a very good reason to change these, you should leave them as they are.\n * Note also that certain values may cause undesired or unexpected results - use judiciously!\n * Additionally, depending on the recognizer implementation, these values may have no effect.\n */\n EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS: number;\n};\n\nexport type ExpoSpeechRecognitionNativeEvents = {\n [K in keyof ExpoSpeechRecognitionNativeEventMap]: (\n event: ExpoSpeechRecognitionNativeEventMap[K],\n ) => void;\n};\n\nexport declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSpeechRecognitionNativeEvents> {\n /**\n * Starts speech recognition.\n */\n start(options: ExpoSpeechRecognitionOptions): void;\n /**\n * Stops speech recognition and attempts to return a final result (through the `result` event).\n */\n stop(): void;\n /**\n * Cancels speech recognition immediately without returning a final result.\n */\n abort(): void;\n /**\n * Presents a dialog to the user to request permissions for using speech recognition and the microphone.\n *\n * For Android, this will request RECORD_AUDIO permission.\n *\n * For iOS, this will request microphone and speech recognition permissions.\n * Once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * Returns the current permission status for speech recognition and the microphone.\n *\n * You may also use `getMicrophonePermissionsAsync` and `getSpeechRecognizerPermissionsAsync` to get the permissions separately.\n */\n getPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * Returns the current permission status for the microphone.\n */\n getMicrophonePermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Presents a dialog to the user to request permissions for using the microphone.\n *\n * For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestMicrophonePermissionsAsync(): Promise<PermissionResponse>;\n /**\n * Returns the current permission status for speech recognition.\n */\n getSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * [iOS only] Presents a dialog to the user to request permissions for using the speech recognizer.\n * This permission is required when `requiresOnDeviceRecognition` is disabled (i.e. network-based recognition)\n *\n * For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,\n * the only way that the permissions can be changed is by the user themselves using the device settings app.\n */\n requestSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;\n /**\n * Returns an array of locales supported by the speech recognizer.\n *\n * Not supported on Android 12 and below (API level 31), this will return an empty array of locales.\n *\n * @throws {\"package_not_found\"} If the service package is not found.\n * @throws {\"error_[number]\"} If there was an error retrieving the supported locales.\n */\n getSupportedLocales(options: {\n /**\n * The package name of the speech recognition service to use.\n *\n * e.g. \"com.google.android.as\" or \"com.samsung.android.bixby.agent\"\n *\n * Warning: the service package (such as Bixby) may not be able to return any results.\n */\n androidRecognitionServicePackage?: string;\n }): Promise<{\n /**\n * All supported languages on the device. This includes both installed and supported languages.\n */\n locales: string[];\n /**\n * These languages are installed on to the device for offline use.\n *\n * This will likely be an empty array if the service package is not \"com.google.android.as\"\n */\n installedLocales: string[];\n }>;\n /**\n * [Android only] Returns an array of package names of speech recognition services that are available on the device.\n *\n * List of all available services as bundle identifiers, e.g. [\"com.google.android.as\", \"com.google.android.tts\"]\n */\n getSpeechRecognitionServices(): string[];\n /**\n * [Android only] Returns the default voice recognition service on the device.\n *\n * @returns empty string if no service is found, or not Android\n */\n getDefaultRecognitionService(): {\n /** e.g. \"com.google.android.tts\" or \"com.google.android.googlequicksearchbox\" */\n packageName: string;\n };\n /**\n * [Android only] Returns the default voice recognition service on the device.\n *\n * e.g. \"com.google.android.googlequicksearchbox\" or \"com.samsung.android.bixby.agent\"\n *\n * @returns empty string if no service is found, or not Android\n */\n getAssistantService(): {\n /** e.g. \"com.google.android.googlequicksearchbox\" or \"com.samsung.android.bixby.agent\" */\n packageName: string;\n };\n /**\n * Whether the on-device speech recognition is available on the device.\n */\n supportsOnDeviceRecognition(): boolean;\n /**\n * Whether the recording feature is available on the device.\n *\n * This mostly applies to Android devices, to check if it's greater than Android 13.\n */\n supportsRecording(): boolean;\n /**\n * Whether on-device speech recognition is available.\n *\n * If this method returns false, `start()` will fail and emit an error event with the code `service-not-allowed` or `language-not-supported`.\n */\n isRecognitionAvailable(): boolean;\n\n /**\n * Downloads the offline model for the specified locale.\n * Note: this is only supported on Android 13 and above.\n */\n androidTriggerOfflineModelDownload(options: {\n /** The locale to download the model for, e.g. \"en-US\" */\n locale: string;\n }): Promise<{\n /**\n * On Android 13, the status will be \"opened_dialog\" indicating that the model download dialog was opened.\n * On Android 14+, the status will be \"download_success\" indicating that the model download was successful.\n * On Android 14+, \"download_canceled\" will be returned if the download was canceled by a user interaction.\n */\n status: \"download_success\" | \"opened_dialog\" | \"download_canceled\";\n message: string;\n }>;\n /**\n * [iOS only] For advanced use cases, you may use this function to set the audio session category and mode.\n *\n * See: https://developer.apple.com/documentation/avfaudio/avaudiosession/1771734-setcategory\n */\n setCategoryIOS(options: SetCategoryOptions): void;\n\n /**\n * [iOS only] Returns the current audio session category and options.\n *\n * See:\n * - [AVAudioSession.Category](https://developer.apple.com/documentation/avfaudio/avaudiosession/category)\n * - [AVAudioSession.CategoryOptions](https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions)\n * - [AVAudioSession.Mode](https://developer.apple.com/documentation/avfaudio/avaudiosession/mode)\n */\n getAudioSessionCategoryAndOptionsIOS(): {\n category: AVAudioSessionCategoryValue;\n categoryOptions: AVAudioSessionCategoryOptionsValue[];\n mode: AVAudioSessionModeValue;\n };\n /**\n * [iOS only] Sets the shared audio session active state.\n *\n * Calls the following on iOS: `AVAudioSession.sharedInstance().setActive(value, options)`\n *\n * See: https://developer.apple.com/documentation/avfaudio/avaudiosession/1616627-setactive\n */\n setAudioSessionActiveIOS(\n value: boolean,\n options?: {\n /** [Default: true] Whether to notify other audio sessions when the active state changes. */\n notifyOthersOnDeactivation: boolean;\n },\n ): void;\n /**\n * Returns the current state of the speech recognizer.\n */\n getStateAsync(): Promise<SpeechRecognitionState>;\n}\n\nexport type SetCategoryOptions = {\n category: AVAudioSessionCategoryValue;\n categoryOptions: AVAudioSessionCategoryOptionsValue[];\n mode?: AVAudioSessionModeValue;\n};\n\ntype SpeechRecognitionState =\n | \"inactive\"\n | \"starting\"\n | \"recognizing\"\n | \"stopping\";\n\n/**\n * [iOS only] See: [AVAudioSession.CategoryOptions](https://developer.apple.com/documentation/avfaudio/avaudiosession/categoryoptions)\n *\n * Use the `AVAudioSessionCategoryOptions` enum to get the correct value.\n */\nexport type AVAudioSessionCategoryOptionsValue =\n (typeof AVAudioSessionCategoryOptions)[keyof typeof AVAudioSessionCategoryOptions];\n\n/**\n * [iOS only] See: [AVAudioSession.Mode](https://developer.apple.com/documentation/avfaudio/avaudiosession/mode)\n *\n * Use the `AVAudioSessionMode` enum to get the correct value.\n */\nexport type AVAudioSessionModeValue =\n (typeof AVAudioSessionMode)[keyof typeof AVAudioSessionMode];\n"]}
|
|
@@ -29,14 +29,17 @@ public class EXSpeechRecognitionPermissionRequester: NSObject, EXPermissionsRequ
|
|
|
29
29
|
|
|
30
30
|
if speechPermission == .authorized && recordPermission == .granted {
|
|
31
31
|
status = EXPermissionStatusGranted
|
|
32
|
-
} else if speechPermission == .denied || recordPermission == .denied
|
|
32
|
+
} else if speechPermission == .denied || recordPermission == .denied
|
|
33
|
+
|| speechPermission == .restricted
|
|
34
|
+
{
|
|
33
35
|
status = EXPermissionStatusDenied
|
|
34
36
|
} else {
|
|
35
37
|
status = EXPermissionStatusUndetermined
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
return [
|
|
39
|
-
"status": status.rawValue
|
|
41
|
+
"status": status.rawValue,
|
|
42
|
+
"restricted": speechPermission == .restricted,
|
|
40
43
|
]
|
|
41
44
|
}
|
|
42
45
|
}
|
|
@@ -105,7 +105,7 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
105
105
|
permissionsManager.register([
|
|
106
106
|
EXSpeechRecognitionPermissionRequester(),
|
|
107
107
|
MicrophoneRequester(),
|
|
108
|
-
SpeechRecognizerRequester()
|
|
108
|
+
SpeechRecognizerRequester(),
|
|
109
109
|
])
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -197,7 +197,7 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
197
197
|
locale: locale
|
|
198
198
|
)
|
|
199
199
|
}
|
|
200
|
-
|
|
200
|
+
|
|
201
201
|
if !options.requiresOnDeviceRecognition {
|
|
202
202
|
guard await SFSpeechRecognizer.hasAuthorizationToRecognize() else {
|
|
203
203
|
sendErrorAndStop(
|
|
@@ -207,7 +207,7 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
207
207
|
return
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
|
|
210
|
+
|
|
211
211
|
guard await AVAudioSession.sharedInstance().hasPermissionToRecord() else {
|
|
212
212
|
sendErrorAndStop(
|
|
213
213
|
error: "not-allowed",
|
|
@@ -346,6 +346,18 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
346
346
|
audioEngine.attach(mixerNode)
|
|
347
347
|
audioEngine.connect(inputNode, to: mixerNode, format: audioFormat)
|
|
348
348
|
|
|
349
|
+
// Configure voice processing if enabled
|
|
350
|
+
if options.iosVoiceProcessingEnabled == true {
|
|
351
|
+
do {
|
|
352
|
+
try audioEngine.inputNode.setVoiceProcessingEnabled(true)
|
|
353
|
+
try audioEngine.outputNode.setVoiceProcessingEnabled(true)
|
|
354
|
+
} catch {
|
|
355
|
+
print(
|
|
356
|
+
"expo-speech-recognition: WARNING - Failed to set voice processing: \(error)"
|
|
357
|
+
)
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
349
361
|
if options.recordingOptions?.persist == true {
|
|
350
362
|
guard let fileAudioFormat = Self.getFileAudioFormat(options: options, engine: audioEngine)
|
|
351
363
|
else {
|
|
@@ -829,20 +841,20 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
829
841
|
/// For testing purposes only
|
|
830
842
|
func playBack(playbackBuffers: [AVAudioPCMBuffer]) {
|
|
831
843
|
guard !playbackBuffers.isEmpty else { return }
|
|
832
|
-
|
|
844
|
+
|
|
833
845
|
playbackEngine = AVAudioEngine()
|
|
834
846
|
playerNode = AVAudioPlayerNode()
|
|
835
|
-
|
|
847
|
+
|
|
836
848
|
guard let playbackEngine = playbackEngine, let playerNode = playerNode else { return }
|
|
837
|
-
|
|
849
|
+
|
|
838
850
|
playbackEngine.attach(playerNode)
|
|
839
851
|
let outputFormat = playbackBuffers[0].format
|
|
840
852
|
playbackEngine.connect(playerNode, to: playbackEngine.mainMixerNode, format: outputFormat)
|
|
841
|
-
|
|
853
|
+
|
|
842
854
|
for buffer in playbackBuffers {
|
|
843
855
|
playerNode.scheduleBuffer(buffer, completionHandler: nil)
|
|
844
856
|
}
|
|
845
|
-
|
|
857
|
+
|
|
846
858
|
do {
|
|
847
859
|
try playbackEngine.start()
|
|
848
860
|
playerNode.play()
|
|
@@ -21,14 +21,15 @@ public class SpeechRecognizerRequester: NSObject, EXPermissionsRequester {
|
|
|
21
21
|
|
|
22
22
|
if speechPermission == .authorized {
|
|
23
23
|
status = EXPermissionStatusGranted
|
|
24
|
-
} else if speechPermission == .denied {
|
|
24
|
+
} else if speechPermission == .denied || speechPermission == .restricted {
|
|
25
25
|
status = EXPermissionStatusDenied
|
|
26
26
|
} else {
|
|
27
27
|
status = EXPermissionStatusUndetermined
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return [
|
|
31
|
-
"status": status.rawValue
|
|
31
|
+
"status": status.rawValue,
|
|
32
|
+
"restricted": speechPermission == .restricted,
|
|
32
33
|
]
|
|
33
34
|
}
|
|
34
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-speech-recognition",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Speech Recognition for React Native Expo projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@changesets/cli": "^2.29.2",
|
|
41
41
|
"@types/dom-speech-recognition": "^0.0.6",
|
|
42
|
-
"@types/react": "~19.0.
|
|
42
|
+
"@types/react": "~19.0.14",
|
|
43
43
|
"expo": "~53.0.0",
|
|
44
44
|
"expo-module-scripts": "^4.1.6",
|
|
45
|
-
"globals": "16.
|
|
45
|
+
"globals": "16.2.0",
|
|
46
46
|
"typescript": "~5.8.3",
|
|
47
|
-
"typescript-eslint": "8.
|
|
47
|
+
"typescript-eslint": "8.33.1"
|
|
48
48
|
},
|
|
49
49
|
"prettier": {
|
|
50
50
|
"trailingComma": "all"
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import type { PermissionResponse } from "expo-modules-core";
|
|
2
2
|
import type { NativeModule } from "expo";
|
|
3
3
|
|
|
4
|
+
export type ExpoSpeechRecognitionPermissionResponse = PermissionResponse & {
|
|
5
|
+
/**
|
|
6
|
+
* Whether the speech recognition is restricted by Content & Privacy Restrictions.
|
|
7
|
+
*
|
|
8
|
+
* This value corresponds to the `restricted` enum of `SFSpeechRecognizer.authorizationStatus()`.
|
|
9
|
+
*
|
|
10
|
+
* This is only available on iOS.
|
|
11
|
+
*/
|
|
12
|
+
restricted?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
4
15
|
import type {
|
|
5
16
|
AudioEncodingAndroid,
|
|
6
17
|
AVAudioSessionCategory,
|
|
@@ -282,6 +293,15 @@ export type ExpoSpeechRecognitionOptions = {
|
|
|
282
293
|
*/
|
|
283
294
|
intervalMillis?: number;
|
|
284
295
|
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* [iOS only] Enabling this option will prevent microphone feedback.
|
|
299
|
+
*
|
|
300
|
+
* When enabled, extra signal processing is applied on the incoming audio, and any audio that is coming from the device is taken out.
|
|
301
|
+
*
|
|
302
|
+
* (This option will place both input and output nodes in voice processing mode as noted in Apple docs: http://developer.apple.com/videos/play/wwdc2019/510/?time=66)
|
|
303
|
+
*/
|
|
304
|
+
iosVoiceProcessingEnabled?: boolean;
|
|
285
305
|
};
|
|
286
306
|
|
|
287
307
|
export type IOSTaskHintValue = (typeof TaskHintIOS)[keyof typeof TaskHintIOS];
|
|
@@ -569,13 +589,13 @@ export declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSp
|
|
|
569
589
|
* Once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
570
590
|
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
571
591
|
*/
|
|
572
|
-
requestPermissionsAsync(): Promise<
|
|
592
|
+
requestPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;
|
|
573
593
|
/**
|
|
574
594
|
* Returns the current permission status for speech recognition and the microphone.
|
|
575
595
|
*
|
|
576
596
|
* You may also use `getMicrophonePermissionsAsync` and `getSpeechRecognizerPermissionsAsync` to get the permissions separately.
|
|
577
597
|
*/
|
|
578
|
-
getPermissionsAsync(): Promise<
|
|
598
|
+
getPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;
|
|
579
599
|
/**
|
|
580
600
|
* Returns the current permission status for the microphone.
|
|
581
601
|
*/
|
|
@@ -590,7 +610,7 @@ export declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSp
|
|
|
590
610
|
/**
|
|
591
611
|
* Returns the current permission status for speech recognition.
|
|
592
612
|
*/
|
|
593
|
-
getSpeechRecognizerPermissionsAsync(): Promise<
|
|
613
|
+
getSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;
|
|
594
614
|
/**
|
|
595
615
|
* [iOS only] Presents a dialog to the user to request permissions for using the speech recognizer.
|
|
596
616
|
* This permission is required when `requiresOnDeviceRecognition` is disabled (i.e. network-based recognition)
|
|
@@ -598,7 +618,7 @@ export declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSp
|
|
|
598
618
|
* For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
599
619
|
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
600
620
|
*/
|
|
601
|
-
requestSpeechRecognizerPermissionsAsync(): Promise<
|
|
621
|
+
requestSpeechRecognizerPermissionsAsync(): Promise<ExpoSpeechRecognitionPermissionResponse>;
|
|
602
622
|
/**
|
|
603
623
|
* Returns an array of locales supported by the speech recognizer.
|
|
604
624
|
*
|