expo-speech-recognition 1.0.0 → 1.0.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 +6 -0
- package/README.md +5 -0
- package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechRecognitionModule.kt +42 -0
- package/build/ExpoSpeechRecognitionModule.types.d.ts +30 -2
- package/build/ExpoSpeechRecognitionModule.types.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.types.js.map +1 -1
- package/build/ExpoSpeechRecognitionModule.web.d.ts +4 -0
- package/build/ExpoSpeechRecognitionModule.web.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.web.js +85 -13
- package/build/ExpoSpeechRecognitionModule.web.js.map +1 -1
- package/ios/ExpoSpeechRecognitionModule.swift +55 -1
- package/ios/ExpoSpeechRecognizer.swift +0 -8
- package/ios/MicrophoneRequester.swift +33 -0
- package/ios/SpeechRecognizerRequester.swift +34 -0
- package/package.json +1 -1
- package/src/ExpoSpeechRecognitionModule.types.ts +30 -2
- package/src/ExpoSpeechRecognitionModule.web.ts +109 -16
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -54,8 +54,13 @@ expo-speech-recognition implements the iOS [`SFSpeechRecognizer`](https://develo
|
|
|
54
54
|
|
|
55
55
|
```
|
|
56
56
|
npm install expo-speech-recognition
|
|
57
|
+
|
|
58
|
+
# Or for older SDKs:
|
|
59
|
+
npm install expo-speech-recognition@sdk-51
|
|
60
|
+
npm install expo-speech-recognition@sdk-50
|
|
57
61
|
```
|
|
58
62
|
|
|
63
|
+
|
|
59
64
|
2. Configure the config plugin.
|
|
60
65
|
|
|
61
66
|
> The config plugin updates the Android App Manifest to include package visibility filtering for `com.google.android.googlequicksearchbox` (Google's Speech Recognition) along with the required permissions for Android and iOS.
|
|
@@ -6,6 +6,7 @@ import android.content.ComponentName
|
|
|
6
6
|
import android.content.Context
|
|
7
7
|
import android.content.Intent
|
|
8
8
|
import android.os.Build
|
|
9
|
+
import android.os.Bundle
|
|
9
10
|
import android.os.Handler
|
|
10
11
|
import android.provider.Settings
|
|
11
12
|
import android.speech.ModelDownloadListener
|
|
@@ -16,6 +17,7 @@ import android.speech.RecognizerIntent
|
|
|
16
17
|
import android.speech.SpeechRecognizer
|
|
17
18
|
import android.util.Log
|
|
18
19
|
import androidx.annotation.RequiresApi
|
|
20
|
+
import expo.modules.interfaces.permissions.PermissionsResponse
|
|
19
21
|
import expo.modules.interfaces.permissions.Permissions.askForPermissionsWithPermissionsManager
|
|
20
22
|
import expo.modules.interfaces.permissions.Permissions.getPermissionsWithPermissionsManager
|
|
21
23
|
import expo.modules.kotlin.Promise
|
|
@@ -143,6 +145,46 @@ class ExpoSpeechRecognitionModule : Module() {
|
|
|
143
145
|
)
|
|
144
146
|
}
|
|
145
147
|
|
|
148
|
+
AsyncFunction("requestMicrophonePermissionsAsync") { promise: Promise ->
|
|
149
|
+
askForPermissionsWithPermissionsManager(
|
|
150
|
+
appContext.permissions,
|
|
151
|
+
promise,
|
|
152
|
+
RECORD_AUDIO,
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
AsyncFunction("getMicrophonePermissionsAsync") { promise: Promise ->
|
|
157
|
+
getPermissionsWithPermissionsManager(
|
|
158
|
+
appContext.permissions,
|
|
159
|
+
promise,
|
|
160
|
+
RECORD_AUDIO,
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
AsyncFunction("getSpeechRecognizerPermissionsAsync") { promise: Promise ->
|
|
165
|
+
Log.w("ExpoSpeechRecognitionModule", "getSpeechRecognizerPermissionsAsync is not supported on Android. Returning a granted permission response.")
|
|
166
|
+
promise.resolve(
|
|
167
|
+
Bundle().apply {
|
|
168
|
+
putString(PermissionsResponse.EXPIRES_KEY, "never")
|
|
169
|
+
putString(PermissionsResponse.STATUS_KEY, "granted")
|
|
170
|
+
putBoolean(PermissionsResponse.CAN_ASK_AGAIN_KEY, false)
|
|
171
|
+
putBoolean(PermissionsResponse.GRANTED_KEY, true)
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
AsyncFunction("requestSpeechRecognizerPermissionsAsync") { promise: Promise ->
|
|
177
|
+
Log.w("ExpoSpeechRecognitionModule", "requestSpeechRecognizerPermissionsAsync is not supported on Android. Returning a granted permission response.")
|
|
178
|
+
promise.resolve(
|
|
179
|
+
Bundle().apply {
|
|
180
|
+
putString(PermissionsResponse.EXPIRES_KEY, "never")
|
|
181
|
+
putString(PermissionsResponse.STATUS_KEY, "granted")
|
|
182
|
+
putBoolean(PermissionsResponse.CAN_ASK_AGAIN_KEY, false)
|
|
183
|
+
putBoolean(PermissionsResponse.GRANTED_KEY, true)
|
|
184
|
+
}
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
146
188
|
AsyncFunction("getStateAsync") { promise: Promise ->
|
|
147
189
|
val state =
|
|
148
190
|
when (expoSpeechService.recognitionState) {
|
|
@@ -519,14 +519,42 @@ export declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSp
|
|
|
519
519
|
/**
|
|
520
520
|
* Presents a dialog to the user to request permissions for using speech recognition and the microphone.
|
|
521
521
|
*
|
|
522
|
-
* For
|
|
522
|
+
* For Android, this will request RECORD_AUDIO permission.
|
|
523
|
+
*
|
|
524
|
+
* For iOS, this will request microphone and speech recognition permissions.
|
|
525
|
+
* Once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
523
526
|
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
524
527
|
*/
|
|
525
528
|
requestPermissionsAsync(): Promise<PermissionResponse>;
|
|
526
529
|
/**
|
|
527
|
-
* Returns the current permission status for
|
|
530
|
+
* Returns the current permission status for speech recognition and the microphone.
|
|
531
|
+
*
|
|
532
|
+
* You may also use `getMicrophonePermissionsAsync` and `getSpeechRecognizerPermissionsAsync` to get the permissions separately.
|
|
528
533
|
*/
|
|
529
534
|
getPermissionsAsync(): Promise<PermissionResponse>;
|
|
535
|
+
/**
|
|
536
|
+
* Returns the current permission status for the microphone.
|
|
537
|
+
*/
|
|
538
|
+
getMicrophonePermissionsAsync(): Promise<PermissionResponse>;
|
|
539
|
+
/**
|
|
540
|
+
* Presents a dialog to the user to request permissions for using the microphone.
|
|
541
|
+
*
|
|
542
|
+
* For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
543
|
+
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
544
|
+
*/
|
|
545
|
+
requestMicrophonePermissionsAsync(): Promise<PermissionResponse>;
|
|
546
|
+
/**
|
|
547
|
+
* Returns the current permission status for speech recognition.
|
|
548
|
+
*/
|
|
549
|
+
getSpeechRecognizerPermissionsAsync(): Promise<PermissionResponse>;
|
|
550
|
+
/**
|
|
551
|
+
* [iOS only] Presents a dialog to the user to request permissions for using the speech recognizer.
|
|
552
|
+
* This permission is required when `requiresOnDeviceRecognition` is disabled (i.e. network-based recognition)
|
|
553
|
+
*
|
|
554
|
+
* For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
555
|
+
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
556
|
+
*/
|
|
557
|
+
requestSpeechRecognizerPermissionsAsync(): Promise<PermissionResponse>;
|
|
530
558
|
/**
|
|
531
559
|
* Returns an array of locales supported by the speech recognizer.
|
|
532
560
|
*
|
|
@@ -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,EACl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,EACnB,mCAAmC,GACnC,0DAA0D,GAC1D,mEAAmE,CAAC;IACxE;;;;;;;;;OASG;IACH,iDAAiD,EAAE,MAAM,CAAC;IAC1D;;;;;;;;OAQG;IACH,wCAAwC,EAAE,MAAM,CAAC;IACjD;;;;;;;;;OASG;IACH,0DAA0D,EAAE,MAAM,CAAC;CACpE,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;KAC7C,CAAC,IAAI,MAAM,mCAAmC,GAAG,CAChD,KAAK,EAAE,mCAAmC,CAAC,CAAC,CAAC,KAC1C,IAAI;CACV,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,+BAAgC,SAAQ,YAAY,CAAC,iCAAiC,CAAC;IAC1G;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI;IAClD;;OAEG;IACH,IAAI,IAAI,IAAI;IACZ;;OAEG;IACH,KAAK,IAAI,IAAI;IACb
|
|
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,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,CAAC;AAEF,MA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CAAC,OAAO,EAAE;QAC1C,yDAAyD;QACzD,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC;QACV;;;;WAIG;QACH,MAAM,EAAE,kBAAkB,GAAG,eAAe,GAAG,mBAAmB,CAAC;QACnE,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF;;;;OAIG;IACH,cAAc,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAEjD;;;;;;;OAOG;IACH,oCAAoC,IAAI;QACtC,QAAQ,EAAE,2BAA2B,CAAC;QACtC,eAAe,EAAE,kCAAkC,EAAE,CAAC;QACtD,IAAI,EAAE,uBAAuB,CAAC;KAC/B;IACD;;;;;;OAMG;IACH,wBAAwB,CACtB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;QACR,4FAA4F;QAC5F,0BAA0B,EAAE,OAAO,CAAC;KACrC,GACA,IAAI;IACP;;OAEG;IACH,aAAa,IAAI,OAAO,CAAC,sBAAsB,CAAC;CACjD;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,2BAA2B,CAAC;IACtC,eAAe,EAAE,kCAAkC,EAAE,CAAC;IACtD,IAAI,CAAC,EAAE,uBAAuB,CAAC;CAChC,CAAC;AAEF,KAAK,sBAAsB,GACvB,UAAU,GACV,UAAU,GACV,aAAa,GACb,UAAU,CAAC;AAEf;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAC5C,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,OAAO,6BAA6B,CAAC,CAAC;AAErF;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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\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 iOS, once a user has granted (or denied) location 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 the microphone and speech recognition.\n */\n getPermissionsAsync(): 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\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"]}
|
|
@@ -14,6 +14,10 @@ declare class ExpoSpeechRecognitionModuleWeb extends NativeModule<ExpoSpeechReco
|
|
|
14
14
|
abort(): void;
|
|
15
15
|
requestPermissionsAsync(): Promise<PermissionResponse>;
|
|
16
16
|
getPermissionsAsync(): Promise<PermissionResponse>;
|
|
17
|
+
getMicrophonePermissionsAsync(): Promise<PermissionResponse>;
|
|
18
|
+
requestMicrophonePermissionsAsync(): Promise<PermissionResponse>;
|
|
19
|
+
getSpeechRecognizerPermissionsAsync(): Promise<PermissionResponse>;
|
|
20
|
+
requestSpeechRecognizerPermissionsAsync(): Promise<PermissionResponse>;
|
|
17
21
|
getSupportedLocales(): Promise<{
|
|
18
22
|
locales: string[];
|
|
19
23
|
installedLocales: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSpeechRecognitionModule.web.d.ts","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OA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B;iBAKN,MAAM,EAAE;0BACC,MAAM,EAAE;;IAQpC,4BAA4B,IACb,MAAM,EAAE;IAGvB,4BAA4B;;;IAM5B,mBAAmB;;;IAMnB,2BAA2B;IAI3B,iBAAiB;IAIjB,kCAAkC;;;;IAUlC,cAAc;IAId,oCAAoC;;;;;IAWpC,wBAAwB;IAIxB,sBAAsB;CAOvB;AAiFD,eAAO,MAAM,2BAA2B,uCAEvC,CAAC"}
|
|
@@ -101,6 +101,7 @@ class ExpoSpeechRecognitionModuleWeb extends NativeModule {
|
|
|
101
101
|
_speechRecognitionRef?.abort();
|
|
102
102
|
}
|
|
103
103
|
requestPermissionsAsync() {
|
|
104
|
+
console.warn("requestPermissionsAsync is not supported on web. Returning a granted permission response.");
|
|
104
105
|
return Promise.resolve({
|
|
105
106
|
granted: true,
|
|
106
107
|
canAskAgain: false,
|
|
@@ -109,12 +110,48 @@ class ExpoSpeechRecognitionModuleWeb extends NativeModule {
|
|
|
109
110
|
});
|
|
110
111
|
}
|
|
111
112
|
getPermissionsAsync() {
|
|
112
|
-
console.warn("getPermissionsAsync is not supported on web. Returning a
|
|
113
|
+
console.warn("getPermissionsAsync is not supported on web. Returning a granted permission response.");
|
|
113
114
|
return Promise.resolve({
|
|
114
|
-
granted:
|
|
115
|
+
granted: true,
|
|
116
|
+
canAskAgain: false,
|
|
117
|
+
expires: "never",
|
|
118
|
+
status: "granted",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
getMicrophonePermissionsAsync() {
|
|
122
|
+
console.warn("getMicrophonePermissionsAsync is not supported on web. Returning a granted permission response.");
|
|
123
|
+
return Promise.resolve({
|
|
124
|
+
granted: true,
|
|
125
|
+
canAskAgain: false,
|
|
126
|
+
expires: "never",
|
|
127
|
+
status: "granted",
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
requestMicrophonePermissionsAsync() {
|
|
131
|
+
console.warn("requestMicrophonePermissionsAsync is not supported on web. Returning a granted permission response.");
|
|
132
|
+
return Promise.resolve({
|
|
133
|
+
granted: true,
|
|
115
134
|
canAskAgain: false,
|
|
116
135
|
expires: "never",
|
|
117
|
-
status: "
|
|
136
|
+
status: "granted",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
getSpeechRecognizerPermissionsAsync() {
|
|
140
|
+
console.warn("getSpeechRecognizerPermissionsAsync is not supported on web. Returning a granted permission response.");
|
|
141
|
+
return Promise.resolve({
|
|
142
|
+
granted: true,
|
|
143
|
+
canAskAgain: false,
|
|
144
|
+
expires: "never",
|
|
145
|
+
status: "granted",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
requestSpeechRecognizerPermissionsAsync() {
|
|
149
|
+
console.warn("requestSpeechRecognizerPermissionsAsync is not supported on web. Returning a granted permission response.");
|
|
150
|
+
return Promise.resolve({
|
|
151
|
+
granted: true,
|
|
152
|
+
canAskAgain: false,
|
|
153
|
+
expires: "never",
|
|
154
|
+
status: "granted",
|
|
118
155
|
});
|
|
119
156
|
}
|
|
120
157
|
async getSupportedLocales() {
|
|
@@ -182,18 +219,53 @@ const webToNativeEventMap = {
|
|
|
182
219
|
error: (ev) => ({ error: ev.error, message: ev.message }),
|
|
183
220
|
nomatch: (ev) => null,
|
|
184
221
|
result: (ev) => {
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
222
|
+
const isFinal = Boolean(ev.results[ev.resultIndex]?.isFinal);
|
|
223
|
+
if (isFinal) {
|
|
224
|
+
const results = [];
|
|
225
|
+
for (let i = 0; i < ev.results[ev.resultIndex].length; i++) {
|
|
226
|
+
const result = ev.results[ev.resultIndex][i];
|
|
227
|
+
results.push({
|
|
228
|
+
transcript: result.transcript,
|
|
229
|
+
confidence: result.confidence,
|
|
230
|
+
segments: [],
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
isFinal: true,
|
|
235
|
+
results,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// Interim results: Append to the transcript
|
|
239
|
+
let transcript = "";
|
|
240
|
+
const segments = [];
|
|
241
|
+
for (let i = ev.resultIndex; i < ev.results.length; i++) {
|
|
242
|
+
const resultList = ev.results[i];
|
|
243
|
+
for (let j = 0; j < resultList.length; j++) {
|
|
244
|
+
const result = resultList[j];
|
|
245
|
+
if (!result) {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
segments.push({
|
|
249
|
+
confidence: result.confidence,
|
|
250
|
+
segment: result.transcript,
|
|
251
|
+
startTimeMillis: 0,
|
|
252
|
+
endTimeMillis: 0,
|
|
253
|
+
});
|
|
254
|
+
if (!isFinal) {
|
|
255
|
+
transcript += result.transcript;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
193
258
|
}
|
|
194
259
|
return {
|
|
195
|
-
isFinal:
|
|
196
|
-
results:
|
|
260
|
+
isFinal: false,
|
|
261
|
+
results: [
|
|
262
|
+
{
|
|
263
|
+
transcript,
|
|
264
|
+
confidence: segments.reduce((acc, curr) => acc + curr.confidence, 0) /
|
|
265
|
+
segments.length,
|
|
266
|
+
segments,
|
|
267
|
+
},
|
|
268
|
+
],
|
|
197
269
|
};
|
|
198
270
|
},
|
|
199
271
|
soundstart: (ev) => null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoSpeechRecognitionModule.web.js","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAOvD,IAAI,qBAAqB,GAA6B,IAAI,CAAC;AAM3D,kEAAkE;AAClE,4EAA4E;AAC5E,MAAM,8BAA+B,SAAQ,YAA+C;IAC1F,gBAAgB,GAKZ,IAAI,GAAG,EAAE,CAAC;IAEd,gBAAgB,GAA0C,IAAI,GAAG,EAAE,CAAC;IAEpE,4CAA4C;IAC5C,iBAAiB,GAAG,C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AE,EAAE,CAAC,IAAI;IACzB,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI;IACnB,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI;CACvB,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,iBAAiB,CAC1D,8BAA8B,CAC/B,CAAC","sourcesContent":["import type { EventSubscription, PermissionResponse } from \"expo-modules-core\";\nimport { registerWebModule, NativeModule } from \"expo\";\nimport type {\n ExpoSpeechRecognitionNativeEventMap,\n ExpoSpeechRecognitionNativeEvents,\n ExpoSpeechRecognitionOptions,\n} from \"./ExpoSpeechRecognitionModule.types\";\n\nlet _speechRecognitionRef: SpeechRecognition | null = null;\n\ntype NativeEventListener = (\n event: SpeechRecognitionEventMap[keyof SpeechRecognitionEventMap],\n) => void;\n\n// It loads the native module object from the JSI or falls back to\n// the bridge module (from NativeModulesProxy) if the remote debugger is on.\nclass ExpoSpeechRecognitionModuleWeb extends NativeModule<ExpoSpeechRecognitionNativeEvents> {\n _clientListeners: Map<\n // Original listener\n ExpoSpeechRecognitionNativeEvents[keyof ExpoSpeechRecognitionNativeEvents],\n // Native listener\n NativeEventListener\n > = new Map();\n\n _nativeListeners: Map<string, Set<NativeEventListener>> = new Map();\n\n // Convert the web event to the native event\n bindEventListener = <T extends keyof SpeechRecognitionEventMap>(\n eventName: T,\n ev: SpeechRecognitionEventMap[T],\n ) => {\n const eventPayload = webToNativeEventMap[eventName]?.(ev);\n\n this.emit(\n eventName,\n // @ts-expect-error payload typings are incorrect\n eventPayload,\n );\n };\n\n addListener<EventName extends keyof ExpoSpeechRecognitionNativeEventMap>(\n eventName: EventName,\n listener: ExpoSpeechRecognitionNativeEvents[EventName],\n ): EventSubscription {\n // Convert the web event to the native event\n\n // @ts-expect-error Not all events are covered here\n const nativeListener = (ev: SpeechRecognitionEventMap[EventName]) => {\n const handler =\n eventName in webToNativeEventMap\n ? webToNativeEventMap[eventName as keyof SpeechRecognitionEventMap]\n : null;\n\n // @ts-expect-error payload typings are incorrect\n const eventPayload = handler?.(ev);\n\n // @ts-expect-error\n listener(eventPayload);\n };\n\n // @ts-expect-error\n _speechRecognitionRef?.addEventListener(eventName, nativeListener);\n if (!this._nativeListeners.has(eventName)) {\n this._nativeListeners.set(eventName, new Set());\n }\n // Add the original listener to the enhanced listeners\n // @ts-expect-error\n this._nativeListeners.get(eventName)?.add(nativeListener);\n // Map the original listener to the enhanced listener\n // @ts-expect-error\n this._clientListeners.set(listener, nativeListener);\n\n const handle = super.addListener(eventName, listener);\n\n return {\n remove: () => {\n // @ts-expect-error\n this._nativeListeners.get(eventName)?.delete(nativeListener);\n this._clientListeners.delete(listener);\n handle.remove();\n },\n };\n }\n\n removeAllListeners(\n eventName: keyof ExpoSpeechRecognitionNativeEventMap,\n ): void {\n // Go through _listeners and remove all listeners for this event\n if (this._nativeListeners.has(eventName)) {\n const nativeListeners = this._nativeListeners.get(eventName);\n if (!nativeListeners) {\n return;\n }\n\n // Remove the enhanced listeners\n for (const [listener, nativeListener] of this._clientListeners) {\n // if nativeListener in listeners, remove it\n if (nativeListeners.has(nativeListener)) {\n // Remove the enhanced listener\n this.removeListener(eventName, listener);\n }\n }\n\n // ...and the native listeners\n for (const listener of nativeListeners) {\n // @ts-expect-error\n this.removeListener(eventName, listener);\n }\n\n // Clean up\n this._nativeListeners.delete(eventName);\n }\n }\n\n start(options: ExpoSpeechRecognitionOptions) {\n const SpeechRecognitionClass =\n typeof webkitSpeechRecognition !== \"undefined\"\n ? webkitSpeechRecognition\n : SpeechRecognition;\n _speechRecognitionRef = new SpeechRecognitionClass();\n _speechRecognitionRef.lang = options.lang ?? \"en-US\";\n _speechRecognitionRef.interimResults = options.interimResults ?? false;\n _speechRecognitionRef.maxAlternatives = options.maxAlternatives ?? 1;\n _speechRecognitionRef.continuous = options.continuous ?? false;\n\n // Re-subscribe to events so that we don't lose them\n // This covers the case where the user has already subscribed to an event prior to calling `start()`\n this._nativeListeners.forEach((listeners, eventName) => {\n for (const listener of listeners) {\n // May already be subscribed\n _speechRecognitionRef?.removeEventListener(eventName, listener);\n _speechRecognitionRef?.addEventListener(eventName, listener);\n }\n });\n\n // Start the speech recognition!\n _speechRecognitionRef.start();\n }\n\n getStateAsync() {\n console.warn(\n \"getStateAsync is not supported on web. Returning 'inactive'.\",\n );\n return Promise.resolve(\"inactive\");\n }\n\n stop() {\n _speechRecognitionRef?.stop();\n }\n abort() {\n _speechRecognitionRef?.abort();\n }\n\n requestPermissionsAsync() {\n return Promise.resolve({\n granted: true,\n canAskAgain: false,\n expires: \"never\",\n status: \"granted\",\n } as PermissionResponse);\n }\n\n getPermissionsAsync() {\n console.warn(\n \"getPermissionsAsync is not supported on web. Returning a denied permission response.\",\n );\n return Promise.resolve({\n granted: false,\n canAskAgain: false,\n expires: \"never\",\n status: \"denied\",\n } as PermissionResponse);\n }\n\n async getSupportedLocales() {\n console.warn(\n \"getSupportedLocales is not supported on web. Returning an empty array.\",\n );\n return {\n locales: [] as string[],\n installedLocales: [] as string[],\n };\n }\n\n // addListener() {}\n\n // removeListeners() {}\n\n getSpeechRecognitionServices() {\n return [] as string[];\n }\n\n getDefaultRecognitionService() {\n return {\n packageName: \"\",\n };\n }\n\n getAssistantService() {\n return {\n packageName: \"\",\n };\n }\n\n supportsOnDeviceRecognition() {\n return false;\n }\n\n supportsRecording() {\n return false;\n }\n\n androidTriggerOfflineModelDownload() {\n console.warn(\n \"androidTriggerOfflineModelDownload is not supported on web. Returning false.\",\n );\n return Promise.resolve({\n status: \"opened_dialog\",\n message: \"Offline model download is not supported on web.\",\n });\n }\n\n setCategoryIOS() {\n console.warn(\"setCategoryIOS is not supported on web.\");\n }\n\n getAudioSessionCategoryAndOptionsIOS() {\n console.warn(\n \"getAudioSessionCategoryAndOptionsIOS is not supported on web.\",\n );\n return {\n category: \"playAndRecord\",\n categoryOptions: [\"defaultToSpeaker\", \"allowBluetooth\"],\n mode: \"measurement\",\n };\n }\n\n setAudioSessionActiveIOS() {\n console.warn(\"setAudioSessionActiveIOS is not supported on web.\");\n }\n\n isRecognitionAvailable() {\n const hasSpeechRecognitionAPI =\n typeof webkitSpeechRecognition !== \"undefined\" ||\n typeof SpeechRecognition !== \"undefined\";\n\n return hasSpeechRecognitionAPI;\n }\n}\n\n/**\n * Convert the web SpeechRecognitionEventMap to the native event map for compatibility\n */\nconst webToNativeEventMap: {\n [K in keyof SpeechRecognitionEventMap]: (\n ev: SpeechRecognitionEventMap[K],\n ) => ExpoSpeechRecognitionNativeEventMap[K];\n} = {\n audioend: (ev) => ({ uri: null }),\n audiostart: (ev) => ({ uri: null }),\n end: (ev) => null,\n error: (ev) => ({ error: ev.error, message: ev.message }),\n nomatch: (ev) => null,\n result: (ev) => {\n const nativeResults: ExpoSpeechRecognitionNativeEventMap[\"result\"][\"results\"] =\n [];\n\n for (let i = 0; i < ev.results[ev.resultIndex].length; i++) {\n const result = ev.results[ev.resultIndex][i];\n nativeResults.push({\n transcript: result.transcript,\n confidence: result.confidence,\n segments: [],\n });\n }\n\n return {\n isFinal: Boolean(ev.results[ev.resultIndex]?.isFinal),\n results: nativeResults,\n };\n },\n soundstart: (ev) => null,\n speechend: (ev) => null,\n speechstart: (ev) => null,\n start: (ev) => null,\n soundend: (ev) => null,\n};\n\nexport const ExpoSpeechRecognitionModule = registerWebModule(\n ExpoSpeechRecognitionModuleWeb,\n);\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoSpeechRecognitionModule.web.js","sourceRoot":"","sources":["../src/ExpoSpeechRecognitionModule.web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAQvD,IAAI,qBAAqB,GAA6B,IAAI,CAAC;AAM3D,kEAAkE;AAClE,4EAA4E;AAC5E,MAAM,8BAA+B,SAAQ,YAA+C;IAC1F,gBAAgB,GAKZ,IAAI,GAAG,EAAE,CAAC;IAEd,gBAAgB,GAA0C,IAAI,GAAG,EAAE,CAAC;IAEpE,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UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC3C,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;gBAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,SAAS;gBACX,CAAC;gBACD,QAAQ,CAAC,IAAI,CAAC;oBACZ,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,OAAO,EAAE,MAAM,CAAC,UAAU;oBAC1B,eAAe,EAAE,CAAC;oBAClB,aAAa,EAAE,CAAC;iBACjB,CAAC,CAAC;gBAEH,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC;gBAClC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE;gBACP;oBACE,UAAU;oBACV,UAAU,EACR,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;wBACxD,QAAQ,CAAC,MAAM;oBACjB,QAAQ;iBACT;aACF;SACF,CAAC;IACJ,CAAC;IACD,UAAU,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI;IACxB,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI;IACvB,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI;IACzB,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI;IACnB,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI;CACvB,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,iBAAiB,CAC1D,8BAA8B,CAC/B,CAAC","sourcesContent":["import type { EventSubscription, PermissionResponse } from \"expo-modules-core\";\nimport { registerWebModule, NativeModule } from \"expo\";\nimport type {\n ExpoSpeechRecognitionNativeEventMap,\n ExpoSpeechRecognitionNativeEvents,\n ExpoSpeechRecognitionOptions,\n ExpoSpeechRecognitionResultSegment,\n} from \"./ExpoSpeechRecognitionModule.types\";\n\nlet _speechRecognitionRef: SpeechRecognition | null = null;\n\ntype NativeEventListener = (\n event: SpeechRecognitionEventMap[keyof SpeechRecognitionEventMap],\n) => void;\n\n// It loads the native module object from the JSI or falls back to\n// the bridge module (from NativeModulesProxy) if the remote debugger is on.\nclass ExpoSpeechRecognitionModuleWeb extends NativeModule<ExpoSpeechRecognitionNativeEvents> {\n _clientListeners: Map<\n // Original listener\n ExpoSpeechRecognitionNativeEvents[keyof ExpoSpeechRecognitionNativeEvents],\n // Native listener\n NativeEventListener\n > = new Map();\n\n _nativeListeners: Map<string, Set<NativeEventListener>> = new Map();\n\n // Convert the web event to the native event\n bindEventListener = <T extends keyof SpeechRecognitionEventMap>(\n eventName: T,\n ev: SpeechRecognitionEventMap[T],\n ) => {\n const eventPayload = webToNativeEventMap[eventName]?.(ev);\n\n this.emit(\n eventName,\n // @ts-expect-error payload typings are incorrect\n eventPayload,\n );\n };\n\n addListener<EventName extends keyof ExpoSpeechRecognitionNativeEventMap>(\n eventName: EventName,\n listener: ExpoSpeechRecognitionNativeEvents[EventName],\n ): EventSubscription {\n // Convert the web event to the native event\n\n // @ts-expect-error Not all events are covered here\n const nativeListener = (ev: SpeechRecognitionEventMap[EventName]) => {\n const handler =\n eventName in webToNativeEventMap\n ? webToNativeEventMap[eventName as keyof SpeechRecognitionEventMap]\n : null;\n\n // @ts-expect-error payload typings are incorrect\n const eventPayload = handler?.(ev);\n\n // @ts-expect-error\n listener(eventPayload);\n };\n\n // @ts-expect-error\n _speechRecognitionRef?.addEventListener(eventName, nativeListener);\n if (!this._nativeListeners.has(eventName)) {\n this._nativeListeners.set(eventName, new Set());\n }\n // Add the original listener to the enhanced listeners\n // @ts-expect-error\n this._nativeListeners.get(eventName)?.add(nativeListener);\n // Map the original listener to the enhanced listener\n // @ts-expect-error\n this._clientListeners.set(listener, nativeListener);\n\n const handle = super.addListener(eventName, listener);\n\n return {\n remove: () => {\n // @ts-expect-error\n this._nativeListeners.get(eventName)?.delete(nativeListener);\n this._clientListeners.delete(listener);\n handle.remove();\n },\n };\n }\n\n removeAllListeners(\n eventName: keyof ExpoSpeechRecognitionNativeEventMap,\n ): void {\n // Go through _listeners and remove all listeners for this event\n if (this._nativeListeners.has(eventName)) {\n const nativeListeners = this._nativeListeners.get(eventName);\n if (!nativeListeners) {\n return;\n }\n\n // Remove the enhanced listeners\n for (const [listener, nativeListener] of this._clientListeners) {\n // if nativeListener in listeners, remove it\n if (nativeListeners.has(nativeListener)) {\n // Remove the enhanced listener\n this.removeListener(eventName, listener);\n }\n }\n\n // ...and the native listeners\n for (const listener of nativeListeners) {\n // @ts-expect-error\n this.removeListener(eventName, listener);\n }\n\n // Clean up\n this._nativeListeners.delete(eventName);\n }\n }\n\n start(options: ExpoSpeechRecognitionOptions) {\n const SpeechRecognitionClass =\n typeof webkitSpeechRecognition !== \"undefined\"\n ? webkitSpeechRecognition\n : SpeechRecognition;\n _speechRecognitionRef = new SpeechRecognitionClass();\n _speechRecognitionRef.lang = options.lang ?? \"en-US\";\n _speechRecognitionRef.interimResults = options.interimResults ?? false;\n _speechRecognitionRef.maxAlternatives = options.maxAlternatives ?? 1;\n _speechRecognitionRef.continuous = options.continuous ?? false;\n\n // Re-subscribe to events so that we don't lose them\n // This covers the case where the user has already subscribed to an event prior to calling `start()`\n this._nativeListeners.forEach((listeners, eventName) => {\n for (const listener of listeners) {\n // May already be subscribed\n _speechRecognitionRef?.removeEventListener(eventName, listener);\n _speechRecognitionRef?.addEventListener(eventName, listener);\n }\n });\n\n // Start the speech recognition!\n _speechRecognitionRef.start();\n }\n\n getStateAsync() {\n console.warn(\n \"getStateAsync is not supported on web. Returning 'inactive'.\",\n );\n return Promise.resolve(\"inactive\");\n }\n\n stop() {\n _speechRecognitionRef?.stop();\n }\n abort() {\n _speechRecognitionRef?.abort();\n }\n\n requestPermissionsAsync() {\n console.warn(\n \"requestPermissionsAsync is not supported on web. Returning a granted permission response.\",\n );\n return Promise.resolve({\n granted: true,\n canAskAgain: false,\n expires: \"never\",\n status: \"granted\",\n } as PermissionResponse);\n }\n\n getPermissionsAsync() {\n console.warn(\n \"getPermissionsAsync is not supported on web. Returning a granted permission response.\",\n );\n return Promise.resolve({\n granted: true,\n canAskAgain: false,\n expires: \"never\",\n status: \"granted\",\n } as PermissionResponse);\n }\n\n getMicrophonePermissionsAsync() {\n console.warn(\n \"getMicrophonePermissionsAsync is not supported on web. Returning a granted permission response.\",\n );\n return Promise.resolve({\n granted: true,\n canAskAgain: false,\n expires: \"never\",\n status: \"granted\",\n } as PermissionResponse);\n }\n\n requestMicrophonePermissionsAsync() {\n console.warn(\n \"requestMicrophonePermissionsAsync is not supported on web. Returning a granted permission response.\",\n );\n return Promise.resolve({\n granted: true,\n canAskAgain: false,\n expires: \"never\",\n status: \"granted\",\n } as PermissionResponse);\n }\n\n getSpeechRecognizerPermissionsAsync() {\n console.warn(\n \"getSpeechRecognizerPermissionsAsync is not supported on web. Returning a granted permission response.\",\n );\n return Promise.resolve({\n granted: true,\n canAskAgain: false,\n expires: \"never\",\n status: \"granted\",\n } as PermissionResponse);\n }\n\n requestSpeechRecognizerPermissionsAsync() {\n console.warn(\n \"requestSpeechRecognizerPermissionsAsync is not supported on web. Returning a granted permission response.\",\n );\n return Promise.resolve({\n granted: true,\n canAskAgain: false,\n expires: \"never\",\n status: \"granted\",\n } as PermissionResponse);\n }\n\n async getSupportedLocales() {\n console.warn(\n \"getSupportedLocales is not supported on web. Returning an empty array.\",\n );\n return {\n locales: [] as string[],\n installedLocales: [] as string[],\n };\n }\n\n // addListener() {}\n\n // removeListeners() {}\n\n getSpeechRecognitionServices() {\n return [] as string[];\n }\n\n getDefaultRecognitionService() {\n return {\n packageName: \"\",\n };\n }\n\n getAssistantService() {\n return {\n packageName: \"\",\n };\n }\n\n supportsOnDeviceRecognition() {\n return false;\n }\n\n supportsRecording() {\n return false;\n }\n\n androidTriggerOfflineModelDownload() {\n console.warn(\n \"androidTriggerOfflineModelDownload is not supported on web. Returning false.\",\n );\n return Promise.resolve({\n status: \"opened_dialog\",\n message: \"Offline model download is not supported on web.\",\n });\n }\n\n setCategoryIOS() {\n console.warn(\"setCategoryIOS is not supported on web.\");\n }\n\n getAudioSessionCategoryAndOptionsIOS() {\n console.warn(\n \"getAudioSessionCategoryAndOptionsIOS is not supported on web.\",\n );\n return {\n category: \"playAndRecord\",\n categoryOptions: [\"defaultToSpeaker\", \"allowBluetooth\"],\n mode: \"measurement\",\n };\n }\n\n setAudioSessionActiveIOS() {\n console.warn(\"setAudioSessionActiveIOS is not supported on web.\");\n }\n\n isRecognitionAvailable() {\n const hasSpeechRecognitionAPI =\n typeof webkitSpeechRecognition !== \"undefined\" ||\n typeof SpeechRecognition !== \"undefined\";\n\n return hasSpeechRecognitionAPI;\n }\n}\n\n/**\n * Convert the web SpeechRecognitionEventMap to the native event map for compatibility\n */\nconst webToNativeEventMap: {\n [K in keyof SpeechRecognitionEventMap]: (\n ev: SpeechRecognitionEventMap[K],\n ) => ExpoSpeechRecognitionNativeEventMap[K];\n} = {\n audioend: (ev) => ({ uri: null }),\n audiostart: (ev) => ({ uri: null }),\n end: (ev) => null,\n error: (ev) => ({ error: ev.error, message: ev.message }),\n nomatch: (ev) => null,\n result: (ev): ExpoSpeechRecognitionNativeEventMap[\"result\"] => {\n const isFinal = Boolean(ev.results[ev.resultIndex]?.isFinal);\n\n if (isFinal) {\n const results: ExpoSpeechRecognitionNativeEventMap[\"result\"][\"results\"] =\n [];\n\n for (let i = 0; i < ev.results[ev.resultIndex].length; i++) {\n const result = ev.results[ev.resultIndex][i];\n results.push({\n transcript: result.transcript,\n confidence: result.confidence,\n segments: [],\n });\n }\n return {\n isFinal: true,\n results,\n };\n }\n\n // Interim results: Append to the transcript\n let transcript = \"\";\n const segments: ExpoSpeechRecognitionResultSegment[] = [];\n\n for (let i = ev.resultIndex; i < ev.results.length; i++) {\n const resultList = ev.results[i];\n\n for (let j = 0; j < resultList.length; j++) {\n const result = resultList[j];\n if (!result) {\n continue;\n }\n segments.push({\n confidence: result.confidence,\n segment: result.transcript,\n startTimeMillis: 0,\n endTimeMillis: 0,\n });\n\n if (!isFinal) {\n transcript += result.transcript;\n }\n }\n }\n\n return {\n isFinal: false,\n results: [\n {\n transcript,\n confidence:\n segments.reduce((acc, curr) => acc + curr.confidence, 0) /\n segments.length,\n segments,\n },\n ],\n };\n },\n soundstart: (ev) => null,\n speechend: (ev) => null,\n speechstart: (ev) => null,\n start: (ev) => null,\n soundend: (ev) => null,\n};\n\nexport const ExpoSpeechRecognitionModule = registerWebModule(\n ExpoSpeechRecognitionModuleWeb,\n);\n"]}
|
|
@@ -104,7 +104,11 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
104
104
|
guard let permissionsManager = appContext?.permissions else {
|
|
105
105
|
return
|
|
106
106
|
}
|
|
107
|
-
permissionsManager.register([
|
|
107
|
+
permissionsManager.register([
|
|
108
|
+
EXSpeechRecognitionPermissionRequester(),
|
|
109
|
+
MicrophoneRequester(),
|
|
110
|
+
SpeechRecognizerRequester()
|
|
111
|
+
])
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
AsyncFunction("requestPermissionsAsync") { (promise: Promise) in
|
|
@@ -129,6 +133,38 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
129
133
|
)
|
|
130
134
|
}
|
|
131
135
|
|
|
136
|
+
AsyncFunction("getMicrophonePermissionsAsync") { (promise: Promise) in
|
|
137
|
+
appContext?.permissions?.getPermissionUsingRequesterClass(
|
|
138
|
+
MicrophoneRequester.self,
|
|
139
|
+
resolve: promise.resolver,
|
|
140
|
+
reject: promise.legacyRejecter
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
AsyncFunction("requestMicrophonePermissionsAsync") { (promise: Promise) in
|
|
145
|
+
appContext?.permissions?.askForPermission(
|
|
146
|
+
usingRequesterClass: MicrophoneRequester.self,
|
|
147
|
+
resolve: promise.resolver,
|
|
148
|
+
reject: promise.legacyRejecter
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
AsyncFunction("getSpeechRecognizerPermissionsAsync") { (promise: Promise) in
|
|
153
|
+
appContext?.permissions?.getPermissionUsingRequesterClass(
|
|
154
|
+
SpeechRecognizerRequester.self,
|
|
155
|
+
resolve: promise.resolver,
|
|
156
|
+
reject: promise.legacyRejecter
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
AsyncFunction("requestSpeechRecognizerPermissionsAsync") { (promise: Promise) in
|
|
161
|
+
appContext?.permissions?.askForPermission(
|
|
162
|
+
usingRequesterClass: SpeechRecognizerRequester.self,
|
|
163
|
+
resolve: promise.resolver,
|
|
164
|
+
reject: promise.legacyRejecter
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
132
168
|
AsyncFunction("getStateAsync") { (promise: Promise) in
|
|
133
169
|
Task {
|
|
134
170
|
let state = await speechRecognizer?.getState()
|
|
@@ -163,6 +199,24 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
163
199
|
locale: locale
|
|
164
200
|
)
|
|
165
201
|
}
|
|
202
|
+
|
|
203
|
+
if !options.requiresOnDeviceRecognition {
|
|
204
|
+
guard await SFSpeechRecognizer.hasAuthorizationToRecognize() else {
|
|
205
|
+
sendErrorAndStop(
|
|
206
|
+
error: "not-allowed",
|
|
207
|
+
message: RecognizerError.notAuthorizedToRecognize.message
|
|
208
|
+
)
|
|
209
|
+
return
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
guard await AVAudioSession.sharedInstance().hasPermissionToRecord() else {
|
|
214
|
+
sendErrorAndStop(
|
|
215
|
+
error: "not-allowed",
|
|
216
|
+
message: RecognizerError.notPermittedToRecord.message
|
|
217
|
+
)
|
|
218
|
+
return
|
|
219
|
+
}
|
|
166
220
|
|
|
167
221
|
// Start recognition!
|
|
168
222
|
await speechRecognizer?.start(
|
|
@@ -56,14 +56,6 @@ actor ExpoSpeechRecognizer: ObservableObject {
|
|
|
56
56
|
guard recognizer != nil else {
|
|
57
57
|
throw RecognizerError.nilRecognizer
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
guard await SFSpeechRecognizer.hasAuthorizationToRecognize() else {
|
|
61
|
-
throw RecognizerError.notAuthorizedToRecognize
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
guard await AVAudioSession.sharedInstance().hasPermissionToRecord() else {
|
|
65
|
-
throw RecognizerError.notPermittedToRecord
|
|
66
|
-
}
|
|
67
59
|
}
|
|
68
60
|
|
|
69
61
|
/// Returns a suitable audio format to use for the speech recognition task and audio file recording.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
public class MicrophoneRequester: NSObject, EXPermissionsRequester {
|
|
4
|
+
static public func permissionType() -> String {
|
|
5
|
+
return "microphone"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
public func requestPermissions(
|
|
9
|
+
resolver resolve: @escaping EXPromiseResolveBlock, rejecter reject: EXPromiseRejectBlock
|
|
10
|
+
) {
|
|
11
|
+
AVAudioSession.sharedInstance().requestRecordPermission { authorized in
|
|
12
|
+
resolve(self.getPermissions())
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public func getPermissions() -> [AnyHashable: Any] {
|
|
17
|
+
var status: EXPermissionStatus
|
|
18
|
+
|
|
19
|
+
let recordPermission = AVAudioSession.sharedInstance().recordPermission
|
|
20
|
+
|
|
21
|
+
if recordPermission == .granted {
|
|
22
|
+
status = EXPermissionStatusGranted
|
|
23
|
+
} else if recordPermission == .denied {
|
|
24
|
+
status = EXPermissionStatusDenied
|
|
25
|
+
} else {
|
|
26
|
+
status = EXPermissionStatusUndetermined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return [
|
|
30
|
+
"status": status.rawValue
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import Speech
|
|
3
|
+
|
|
4
|
+
public class SpeechRecognizerRequester: NSObject, EXPermissionsRequester {
|
|
5
|
+
static public func permissionType() -> String {
|
|
6
|
+
return "speechRecognizer"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public func requestPermissions(
|
|
10
|
+
resolver resolve: @escaping EXPromiseResolveBlock, rejecter reject: EXPromiseRejectBlock
|
|
11
|
+
) {
|
|
12
|
+
SFSpeechRecognizer.requestAuthorization { status in
|
|
13
|
+
resolve(self.getPermissions())
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public func getPermissions() -> [AnyHashable: Any] {
|
|
18
|
+
var status: EXPermissionStatus
|
|
19
|
+
|
|
20
|
+
let speechPermission = SFSpeechRecognizer.authorizationStatus()
|
|
21
|
+
|
|
22
|
+
if speechPermission == .authorized {
|
|
23
|
+
status = EXPermissionStatusGranted
|
|
24
|
+
} else if speechPermission == .denied {
|
|
25
|
+
status = EXPermissionStatusDenied
|
|
26
|
+
} else {
|
|
27
|
+
status = EXPermissionStatusUndetermined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return [
|
|
31
|
+
"status": status.rawValue
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -563,14 +563,42 @@ export declare class ExpoSpeechRecognitionModuleType extends NativeModule<ExpoSp
|
|
|
563
563
|
/**
|
|
564
564
|
* Presents a dialog to the user to request permissions for using speech recognition and the microphone.
|
|
565
565
|
*
|
|
566
|
-
* For
|
|
566
|
+
* For Android, this will request RECORD_AUDIO permission.
|
|
567
|
+
*
|
|
568
|
+
* For iOS, this will request microphone and speech recognition permissions.
|
|
569
|
+
* Once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
567
570
|
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
568
571
|
*/
|
|
569
572
|
requestPermissionsAsync(): Promise<PermissionResponse>;
|
|
570
573
|
/**
|
|
571
|
-
* Returns the current permission status for
|
|
574
|
+
* Returns the current permission status for speech recognition and the microphone.
|
|
575
|
+
*
|
|
576
|
+
* You may also use `getMicrophonePermissionsAsync` and `getSpeechRecognizerPermissionsAsync` to get the permissions separately.
|
|
572
577
|
*/
|
|
573
578
|
getPermissionsAsync(): Promise<PermissionResponse>;
|
|
579
|
+
/**
|
|
580
|
+
* Returns the current permission status for the microphone.
|
|
581
|
+
*/
|
|
582
|
+
getMicrophonePermissionsAsync(): Promise<PermissionResponse>;
|
|
583
|
+
/**
|
|
584
|
+
* Presents a dialog to the user to request permissions for using the microphone.
|
|
585
|
+
*
|
|
586
|
+
* For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
587
|
+
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
588
|
+
*/
|
|
589
|
+
requestMicrophonePermissionsAsync(): Promise<PermissionResponse>;
|
|
590
|
+
/**
|
|
591
|
+
* Returns the current permission status for speech recognition.
|
|
592
|
+
*/
|
|
593
|
+
getSpeechRecognizerPermissionsAsync(): Promise<PermissionResponse>;
|
|
594
|
+
/**
|
|
595
|
+
* [iOS only] Presents a dialog to the user to request permissions for using the speech recognizer.
|
|
596
|
+
* This permission is required when `requiresOnDeviceRecognition` is disabled (i.e. network-based recognition)
|
|
597
|
+
*
|
|
598
|
+
* For iOS, once a user has granted (or denied) permissions by responding to the original permission request dialog,
|
|
599
|
+
* the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
600
|
+
*/
|
|
601
|
+
requestSpeechRecognizerPermissionsAsync(): Promise<PermissionResponse>;
|
|
574
602
|
/**
|
|
575
603
|
* Returns an array of locales supported by the speech recognizer.
|
|
576
604
|
*
|
|
@@ -4,6 +4,7 @@ import type {
|
|
|
4
4
|
ExpoSpeechRecognitionNativeEventMap,
|
|
5
5
|
ExpoSpeechRecognitionNativeEvents,
|
|
6
6
|
ExpoSpeechRecognitionOptions,
|
|
7
|
+
ExpoSpeechRecognitionResultSegment,
|
|
7
8
|
} from "./ExpoSpeechRecognitionModule.types";
|
|
8
9
|
|
|
9
10
|
let _speechRecognitionRef: SpeechRecognition | null = null;
|
|
@@ -152,6 +153,9 @@ class ExpoSpeechRecognitionModuleWeb extends NativeModule<ExpoSpeechRecognitionN
|
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
requestPermissionsAsync() {
|
|
156
|
+
console.warn(
|
|
157
|
+
"requestPermissionsAsync is not supported on web. Returning a granted permission response.",
|
|
158
|
+
);
|
|
155
159
|
return Promise.resolve({
|
|
156
160
|
granted: true,
|
|
157
161
|
canAskAgain: false,
|
|
@@ -162,13 +166,61 @@ class ExpoSpeechRecognitionModuleWeb extends NativeModule<ExpoSpeechRecognitionN
|
|
|
162
166
|
|
|
163
167
|
getPermissionsAsync() {
|
|
164
168
|
console.warn(
|
|
165
|
-
"getPermissionsAsync is not supported on web. Returning a
|
|
169
|
+
"getPermissionsAsync is not supported on web. Returning a granted permission response.",
|
|
170
|
+
);
|
|
171
|
+
return Promise.resolve({
|
|
172
|
+
granted: true,
|
|
173
|
+
canAskAgain: false,
|
|
174
|
+
expires: "never",
|
|
175
|
+
status: "granted",
|
|
176
|
+
} as PermissionResponse);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
getMicrophonePermissionsAsync() {
|
|
180
|
+
console.warn(
|
|
181
|
+
"getMicrophonePermissionsAsync is not supported on web. Returning a granted permission response.",
|
|
182
|
+
);
|
|
183
|
+
return Promise.resolve({
|
|
184
|
+
granted: true,
|
|
185
|
+
canAskAgain: false,
|
|
186
|
+
expires: "never",
|
|
187
|
+
status: "granted",
|
|
188
|
+
} as PermissionResponse);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
requestMicrophonePermissionsAsync() {
|
|
192
|
+
console.warn(
|
|
193
|
+
"requestMicrophonePermissionsAsync is not supported on web. Returning a granted permission response.",
|
|
194
|
+
);
|
|
195
|
+
return Promise.resolve({
|
|
196
|
+
granted: true,
|
|
197
|
+
canAskAgain: false,
|
|
198
|
+
expires: "never",
|
|
199
|
+
status: "granted",
|
|
200
|
+
} as PermissionResponse);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
getSpeechRecognizerPermissionsAsync() {
|
|
204
|
+
console.warn(
|
|
205
|
+
"getSpeechRecognizerPermissionsAsync is not supported on web. Returning a granted permission response.",
|
|
206
|
+
);
|
|
207
|
+
return Promise.resolve({
|
|
208
|
+
granted: true,
|
|
209
|
+
canAskAgain: false,
|
|
210
|
+
expires: "never",
|
|
211
|
+
status: "granted",
|
|
212
|
+
} as PermissionResponse);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
requestSpeechRecognizerPermissionsAsync() {
|
|
216
|
+
console.warn(
|
|
217
|
+
"requestSpeechRecognizerPermissionsAsync is not supported on web. Returning a granted permission response.",
|
|
166
218
|
);
|
|
167
219
|
return Promise.resolve({
|
|
168
|
-
granted:
|
|
220
|
+
granted: true,
|
|
169
221
|
canAskAgain: false,
|
|
170
222
|
expires: "never",
|
|
171
|
-
status: "
|
|
223
|
+
status: "granted",
|
|
172
224
|
} as PermissionResponse);
|
|
173
225
|
}
|
|
174
226
|
|
|
@@ -261,22 +313,63 @@ const webToNativeEventMap: {
|
|
|
261
313
|
end: (ev) => null,
|
|
262
314
|
error: (ev) => ({ error: ev.error, message: ev.message }),
|
|
263
315
|
nomatch: (ev) => null,
|
|
264
|
-
result: (ev) => {
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
316
|
+
result: (ev): ExpoSpeechRecognitionNativeEventMap["result"] => {
|
|
317
|
+
const isFinal = Boolean(ev.results[ev.resultIndex]?.isFinal);
|
|
318
|
+
|
|
319
|
+
if (isFinal) {
|
|
320
|
+
const results: ExpoSpeechRecognitionNativeEventMap["result"]["results"] =
|
|
321
|
+
[];
|
|
322
|
+
|
|
323
|
+
for (let i = 0; i < ev.results[ev.resultIndex].length; i++) {
|
|
324
|
+
const result = ev.results[ev.resultIndex][i];
|
|
325
|
+
results.push({
|
|
326
|
+
transcript: result.transcript,
|
|
327
|
+
confidence: result.confidence,
|
|
328
|
+
segments: [],
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
isFinal: true,
|
|
333
|
+
results,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Interim results: Append to the transcript
|
|
338
|
+
let transcript = "";
|
|
339
|
+
const segments: ExpoSpeechRecognitionResultSegment[] = [];
|
|
340
|
+
|
|
341
|
+
for (let i = ev.resultIndex; i < ev.results.length; i++) {
|
|
342
|
+
const resultList = ev.results[i];
|
|
343
|
+
|
|
344
|
+
for (let j = 0; j < resultList.length; j++) {
|
|
345
|
+
const result = resultList[j];
|
|
346
|
+
if (!result) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
segments.push({
|
|
350
|
+
confidence: result.confidence,
|
|
351
|
+
segment: result.transcript,
|
|
352
|
+
startTimeMillis: 0,
|
|
353
|
+
endTimeMillis: 0,
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
if (!isFinal) {
|
|
357
|
+
transcript += result.transcript;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
275
360
|
}
|
|
276
361
|
|
|
277
362
|
return {
|
|
278
|
-
isFinal:
|
|
279
|
-
results:
|
|
363
|
+
isFinal: false,
|
|
364
|
+
results: [
|
|
365
|
+
{
|
|
366
|
+
transcript,
|
|
367
|
+
confidence:
|
|
368
|
+
segments.reduce((acc, curr) => acc + curr.confidence, 0) /
|
|
369
|
+
segments.length,
|
|
370
|
+
segments,
|
|
371
|
+
},
|
|
372
|
+
],
|
|
280
373
|
};
|
|
281
374
|
},
|
|
282
375
|
soundstart: (ev) => null,
|