expo-speech-recognition 0.2.24 → 0.2.25
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 +7 -0
- package/README.md +71 -32
- package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechRecognitionModule.kt +2 -0
- package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechService.kt +37 -3
- package/build/ExpoSpeechRecognitionModule.types.d.ts +29 -1
- package/build/ExpoSpeechRecognitionModule.types.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.types.js.map +1 -1
- package/ios/ExpoSpeechRecognitionModule.swift +2 -0
- package/package.json +6 -1
- package/src/ExpoSpeechRecognitionModule.types.ts +30 -1
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ expo-speech-recognition implements the iOS [`SFSpeechRecognizer`](https://develo
|
|
|
24
24
|
- [Polyfilling the Web SpeechRecognition API](#polyfilling-the-web-speechrecognition-api)
|
|
25
25
|
- [Muting the beep sound on Android](#muting-the-beep-sound-on-android)
|
|
26
26
|
- [Improving accuracy of single-word prompts](#improving-accuracy-of-single-word-prompts)
|
|
27
|
+
- [Language Detection](#language-detection)
|
|
27
28
|
- [Platform Compatibility Table](#platform-compatibility-table)
|
|
28
29
|
- [Common Troubleshooting issues](#common-troubleshooting-issues)
|
|
29
30
|
- [Android issues](#android-issues)
|
|
@@ -36,14 +37,14 @@ expo-speech-recognition implements the iOS [`SFSpeechRecognizer`](https://develo
|
|
|
36
37
|
- [getPermissionsAsync()](#getpermissionsasync-promisepermissionresponse)
|
|
37
38
|
- [getStateAsync()](#getstateasync-promisespeechrecognitionstate)
|
|
38
39
|
- [addSpeechRecognitionListener()](#addspeechrecognitionlistener)
|
|
39
|
-
- [getSupportedLocales()](#getsupportedlocales
|
|
40
|
+
- [getSupportedLocales()](#getsupportedlocales)
|
|
40
41
|
- [getSpeechRecognitionServices()](#getspeechrecognitionservices-string-android-only)
|
|
41
42
|
- [getDefaultRecognitionService()](#getdefaultrecognitionservice--packagename-string--android-only)
|
|
42
43
|
- [getAssistantService()](#getassistantservice--packagename-string--android-only)
|
|
43
44
|
- [isRecognitionAvailable()](#isrecognitionavailable-boolean)
|
|
44
45
|
- [supportsOnDeviceRecognition()](#supportsondevicerecognition-boolean)
|
|
45
46
|
- [supportsRecording()](#supportsrecording-boolean)
|
|
46
|
-
- [androidTriggerOfflineModelDownload()](#androidtriggerofflinemodeldownload
|
|
47
|
+
- [androidTriggerOfflineModelDownload()](#androidtriggerofflinemodeldownload)
|
|
47
48
|
- [setCategoryIOS()](#setcategoryios-void-ios-only)
|
|
48
49
|
- [getAudioSessionCategoryAndOptionsIOS()](#getaudiosessioncategoryandoptionsios-ios-only)
|
|
49
50
|
- [setAudioSessionActiveIOS()](#setaudiosessionactiveiosvalue-boolean-options--notifyothersondeactivation-boolean--void)
|
|
@@ -98,10 +99,13 @@ If you've just created a new Expo project or have only been using the Expo SDK s
|
|
|
98
99
|
After completing **Step 2: Configure the config plugin**, follow these steps:
|
|
99
100
|
|
|
100
101
|
- To (re)-generate the native Android project, run:
|
|
102
|
+
|
|
101
103
|
```bash
|
|
102
104
|
npx expo run:android
|
|
103
105
|
```
|
|
106
|
+
|
|
104
107
|
- To (re)-generate the native iOS project, run:
|
|
108
|
+
|
|
105
109
|
```bash
|
|
106
110
|
npx expo run:ios
|
|
107
111
|
```
|
|
@@ -138,7 +142,7 @@ function App() {
|
|
|
138
142
|
setTranscript(event.results[0]?.transcript);
|
|
139
143
|
});
|
|
140
144
|
useSpeechRecognitionEvent("error", (event) => {
|
|
141
|
-
console.log("error code:", event.error, "error
|
|
145
|
+
console.log("error code:", event.error, "error message:", event.message);
|
|
142
146
|
});
|
|
143
147
|
|
|
144
148
|
const handleStart = async () => {
|
|
@@ -228,7 +232,7 @@ const resultListener = addSpeechRecognitionListener("result", (event) => {
|
|
|
228
232
|
});
|
|
229
233
|
|
|
230
234
|
const errorListener = addSpeechRecognitionListener("error", (event) => {
|
|
231
|
-
console.log("error code:", event.error, "error
|
|
235
|
+
console.log("error code:", event.error, "error message:", event.message);
|
|
232
236
|
});
|
|
233
237
|
|
|
234
238
|
// Start speech recognition
|
|
@@ -247,6 +251,7 @@ ExpoSpeechRecognitionModule.start({
|
|
|
247
251
|
// [Default: false] Prevent device from sending audio over the network. Only enabled if the device supports it.
|
|
248
252
|
requiresOnDeviceRecognition: false,
|
|
249
253
|
// [Default: false] Include punctuation in the recognition results. This applies to full stops and commas.
|
|
254
|
+
// Not supported on Android 12 and below. On Android 13+, only supported when on-device recognition is enabled.
|
|
250
255
|
addsPunctuation: false,
|
|
251
256
|
// [Default: undefined] Short custom phrases that are unique to your app.
|
|
252
257
|
contextualStrings: ["Carlsen", "Nepomniachtchi", "Praggnanandhaa"],
|
|
@@ -321,18 +326,19 @@ ExpoSpeechRecognitionModule.abort();
|
|
|
321
326
|
|
|
322
327
|
Events are largely based on the [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition). The following events are supported:
|
|
323
328
|
|
|
324
|
-
| Event Name
|
|
325
|
-
|
|
|
326
|
-
| `audiostart`
|
|
327
|
-
| `audioend`
|
|
328
|
-
| `end`
|
|
329
|
-
| `error`
|
|
330
|
-
| `nomatch`
|
|
331
|
-
| `result`
|
|
332
|
-
| `speechstart`
|
|
333
|
-
| `speechend`
|
|
334
|
-
| `start`
|
|
335
|
-
| `volumechange`
|
|
329
|
+
| Event Name | Description | Notes |
|
|
330
|
+
| ------------------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
331
|
+
| `audiostart` | Audio capturing has started | Includes the `uri` if `recordingOptions.persist` is enabled. |
|
|
332
|
+
| `audioend` | Audio capturing has ended | Includes the `uri` if `recordingOptions.persist` is enabled. |
|
|
333
|
+
| `end` | Speech recognition service has disconnected. | This should always be the last event dispatched, including after errors. |
|
|
334
|
+
| `error` | Fired when a speech recognition error occurs. | You'll also receive an `error` event (with code "aborted") when calling `.abort()` |
|
|
335
|
+
| `nomatch` | Speech recognition service returns a final result with no significant recognition. | You may have non-final results recognized. This may get emitted after cancellation. |
|
|
336
|
+
| `result` | Speech recognition service returns a word or phrase has been positively recognized. | On Android, continous mode runs as a segmented session, meaning when a final result is reached, additional partial and final results will cover a new segment separate from the previous final result. On iOS, you should expect one final result before speech recognition has stopped. |
|
|
337
|
+
| `speechstart` | Fired when any sound — recognizable speech or not — has been detected | On iOS, this will fire once in the session after a result has occurred |
|
|
338
|
+
| `speechend` | Fired when speech recognized by the speech recognition service has stopped being detected. | Not supported yet on iOS |
|
|
339
|
+
| `start` | Speech recognition has started | Use this event to indicate to the user when to speak. |
|
|
340
|
+
| `volumechange` | Fired when the input volume changes. | Returns a value between -2 and 10 indicating the volume of the input audio. Consider anything below 0 to be inaudible. |
|
|
341
|
+
| `languagedetection` | Called when the language detection (and switching) results are available. | Android 14+ only with `com.google.android.as`. Enabled with `EXTRA_ENABLE_LANGUAGE_DETECTION` in the `androidIntent` option when starting. Also can be called multiple times by enabling `EXTRA_ENABLE_LANGUAGE_SWITCH`. |
|
|
336
342
|
|
|
337
343
|
## Handling Errors
|
|
338
344
|
|
|
@@ -346,12 +352,12 @@ import {
|
|
|
346
352
|
} from "expo-speech-recognition";
|
|
347
353
|
|
|
348
354
|
addSpeechRecognitionListener("error", (event) => {
|
|
349
|
-
console.log("error code:", event.error, "error
|
|
355
|
+
console.log("error code:", event.error, "error message:", event.message);
|
|
350
356
|
});
|
|
351
357
|
|
|
352
358
|
// or through the `useSpeechRecognitionEvent` hook
|
|
353
359
|
useSpeechRecognitionEvent("error", (event) => {
|
|
354
|
-
console.log("error code:", event.error, "error
|
|
360
|
+
console.log("error code:", event.error, "error message:", event.message);
|
|
355
361
|
});
|
|
356
362
|
|
|
357
363
|
// or through the `ExpoSpeechRecognitionErrorCode` type
|
|
@@ -551,10 +557,15 @@ You can use the `volumeChangeEventOptions.enabled` option to enable volume meter
|
|
|
551
557
|
See: [VolumeMeteringAvatar.tsx](https://github.com/jamsch/expo-speech-recognition/tree/main/example/components/VolumeMeteringAvatar.tsx) for a complete example that involves using `react-native-reanimated` to animate the volume metering.
|
|
552
558
|
|
|
553
559
|
```tsx
|
|
554
|
-
import {
|
|
560
|
+
import { Button } from "react-native";
|
|
561
|
+
import {
|
|
562
|
+
ExpoSpeechRecognitionModule,
|
|
563
|
+
useSpeechRecognitionEvent,
|
|
564
|
+
} from "expo-speech-recognition";
|
|
555
565
|
|
|
556
|
-
function
|
|
566
|
+
function VolumeMeteringExample() {
|
|
557
567
|
useSpeechRecognitionEvent("volumechange", (event) => {
|
|
568
|
+
// a value between -2 and 10. <= 0 is inaudible
|
|
558
569
|
console.log("Volume changed to:", event.value);
|
|
559
570
|
});
|
|
560
571
|
|
|
@@ -563,17 +574,13 @@ function VolumeMeteringAvatar() {
|
|
|
563
574
|
lang: "en-US",
|
|
564
575
|
volumeChangeEventOptions: {
|
|
565
576
|
enabled: true,
|
|
577
|
+
// how often you want to receive the volumechange event
|
|
566
578
|
intervalMillis: 300,
|
|
567
579
|
},
|
|
568
580
|
});
|
|
569
581
|
};
|
|
570
582
|
|
|
571
|
-
return
|
|
572
|
-
<View>
|
|
573
|
-
<Button title="Start" onPress={handleStart} />
|
|
574
|
-
<Text>Volume: {volume}</Text>
|
|
575
|
-
</View>
|
|
576
|
-
);
|
|
583
|
+
return <Button title="Start" onPress={handleStart} />;
|
|
577
584
|
}
|
|
578
585
|
```
|
|
579
586
|
|
|
@@ -642,7 +649,7 @@ const handleResult = (event: SpeechRecognitionEvent) => {
|
|
|
642
649
|
recognition.registerEventListener("result", handleResult);
|
|
643
650
|
|
|
644
651
|
recognition.registerEventListener("error", (event) => {
|
|
645
|
-
console.log("error code:", event.error, "error
|
|
652
|
+
console.log("error code:", event.error, "error message:", event.message);
|
|
646
653
|
});
|
|
647
654
|
|
|
648
655
|
recognition.registerEventListener("end", (event) => console.log("ended!"));
|
|
@@ -694,6 +701,39 @@ You may notice that after saying short syllables, words, letters, or numbers (e.
|
|
|
694
701
|
- For both platforms, you also may want to consider using on-device recognition. On Android this seems to work well for single-word prompts.
|
|
695
702
|
- Alternatively, you may want to consider recording the recognized audio and sending it to an external service for further processing. See [Persisting Audio Recordings](#persisting-audio-recordings) for more information. Note that some services (such as the Google Speech API) may require an audio file with a duration of at least 3 seconds.
|
|
696
703
|
|
|
704
|
+
## Language Detection
|
|
705
|
+
|
|
706
|
+
> [!NOTE]
|
|
707
|
+
> This feature is currently only available on Android 14+ using the `com.google.android.as` service package.
|
|
708
|
+
|
|
709
|
+
You can use the `languagedetection` event to get the detected language and confidence level. This feature has a few requirements:
|
|
710
|
+
|
|
711
|
+
- Android 14+ only.
|
|
712
|
+
- The `com.google.android.as` (on-device recognition) service package must be selected. This seems to be the only service that supports language detection as of writing this.
|
|
713
|
+
- You must enable `EXTRA_ENABLE_LANGUAGE_DETECTION` in the `androidIntentOptions` when starting the recognition.
|
|
714
|
+
- Optional: You can enable `EXTRA_ENABLE_LANGUAGE_SWITCH` to allow the user to switch languages, however **keep in mind that you need the language model to be downloaded for this to work**. Refer to [androidTriggerOfflineModelDownload()](#androidtriggerofflinemodeldownload) to download a model, and [getSupportedLocales()](#getsupportedlocales) to get the list of downloaded on-device locales.
|
|
715
|
+
|
|
716
|
+
Example:
|
|
717
|
+
|
|
718
|
+
```tsx
|
|
719
|
+
import { useSpeechRecognitionEvent } from "expo-speech-recognition";
|
|
720
|
+
|
|
721
|
+
useSpeechRecognitionEvent("languagedetection", (event) => {
|
|
722
|
+
console.log("Language detected:", event.detectedLanguage); // e.g. "en-us"
|
|
723
|
+
console.log("Confidence:", event.confidence); // A value between 0.0 and 1.0
|
|
724
|
+
console.log("Top locale alternatives:", event.topLocaleAlternatives); // e.g. ["en-au", "en-gb"]
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
// Start recognition
|
|
728
|
+
ExpoSpeechRecognitionModule.start({
|
|
729
|
+
androidIntentOptions: {
|
|
730
|
+
EXTRA_ENABLE_LANGUAGE_DETECTION: true,
|
|
731
|
+
EXTRA_ENABLE_LANGUAGE_SWITCH: true,
|
|
732
|
+
},
|
|
733
|
+
androidRecognitionServicePackage: "com.google.android.as", // or set "requiresOnDeviceRecognition" to true
|
|
734
|
+
});
|
|
735
|
+
```
|
|
736
|
+
|
|
697
737
|
## Platform Compatibility Table
|
|
698
738
|
|
|
699
739
|
As of 7 Aug 2024, the following platforms are supported:
|
|
@@ -789,10 +829,9 @@ ExpoSpeechRecognitionModule.abort();
|
|
|
789
829
|
|
|
790
830
|
### `requestPermissionsAsync(): Promise<PermissionResponse>`
|
|
791
831
|
|
|
792
|
-
Presents a dialog to the user to request
|
|
832
|
+
Presents a dialog to the user to request the necessary permissions.
|
|
793
833
|
|
|
794
|
-
For iOS,
|
|
795
|
-
the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
834
|
+
For iOS, this requests two permissions: record permissions (to access the microphone), and speech recognition permissions. Once a user has granted (or denied) permissions by responding to the original permission request dialog, the only way that the permissions can be changed is by the user themselves using the device settings app.
|
|
796
835
|
|
|
797
836
|
```ts
|
|
798
837
|
import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
|
|
@@ -850,7 +889,7 @@ const listener = addSpeechRecognitionListener("result", (event) => {
|
|
|
850
889
|
listener.remove();
|
|
851
890
|
```
|
|
852
891
|
|
|
853
|
-
### `getSupportedLocales()
|
|
892
|
+
### `getSupportedLocales()`
|
|
854
893
|
|
|
855
894
|
> [!NOTE]
|
|
856
895
|
> Not supported on Android 12 and below
|
|
@@ -964,7 +1003,7 @@ const available = supportsRecording();
|
|
|
964
1003
|
console.log("Recording available:", available);
|
|
965
1004
|
```
|
|
966
1005
|
|
|
967
|
-
### `androidTriggerOfflineModelDownload(
|
|
1006
|
+
### `androidTriggerOfflineModelDownload()`
|
|
968
1007
|
|
|
969
1008
|
Users on Android devices will first need to download the offline model for the locale they want to use in order to use on-device speech recognition (i.e. the `requiresOnDeviceRecognition` setting in the `start` options).
|
|
970
1009
|
|
|
@@ -86,6 +86,8 @@ class ExpoSpeechRecognitionModule : Module() {
|
|
|
86
86
|
"start",
|
|
87
87
|
// Called when there's results (as a string array, not API compliant)
|
|
88
88
|
"results",
|
|
89
|
+
// Called when the language detection (and switching) results are available.
|
|
90
|
+
"languagedetection",
|
|
89
91
|
// Fired when the input volume changes
|
|
90
92
|
"volumechange",
|
|
91
93
|
)
|
|
@@ -60,6 +60,9 @@ class ExpoSpeechService(
|
|
|
60
60
|
private var delayedFileStreamer: DelayedFileStreamer? = null
|
|
61
61
|
private var soundState = SoundState.INACTIVE
|
|
62
62
|
|
|
63
|
+
private var lastDetectedLanguage: String? = null
|
|
64
|
+
private var lastLanguageConfidence: Float? = null
|
|
65
|
+
|
|
63
66
|
var recognitionState = RecognitionState.INACTIVE
|
|
64
67
|
|
|
65
68
|
companion object {
|
|
@@ -121,6 +124,8 @@ class ExpoSpeechService(
|
|
|
121
124
|
audioRecorder = null
|
|
122
125
|
delayedFileStreamer?.close()
|
|
123
126
|
delayedFileStreamer = null
|
|
127
|
+
lastDetectedLanguage = null
|
|
128
|
+
lastLanguageConfidence = null
|
|
124
129
|
recognitionState = RecognitionState.STARTING
|
|
125
130
|
soundState = SoundState.INACTIVE
|
|
126
131
|
lastVolumeChangeEventTime = 0L
|
|
@@ -433,12 +438,12 @@ class ExpoSpeechService(
|
|
|
433
438
|
*/
|
|
434
439
|
private fun resolveSourceUri(sourceUri: String): File =
|
|
435
440
|
when {
|
|
436
|
-
// Local file path without URI scheme
|
|
437
|
-
!sourceUri.startsWith("https://") && !sourceUri.startsWith("file://") -> File(sourceUri)
|
|
438
|
-
|
|
439
441
|
// File URI
|
|
440
442
|
sourceUri.startsWith("file://") -> File(URI(sourceUri))
|
|
441
443
|
|
|
444
|
+
// Local file path without URI scheme
|
|
445
|
+
!sourceUri.startsWith("https://") -> File(sourceUri)
|
|
446
|
+
|
|
442
447
|
// HTTP URI - throw an error
|
|
443
448
|
else -> {
|
|
444
449
|
throw Exception("HTTP URI is not supported. Use expo-file-system to download the file.")
|
|
@@ -581,6 +586,15 @@ class ExpoSpeechService(
|
|
|
581
586
|
else -> 0.0f
|
|
582
587
|
}
|
|
583
588
|
|
|
589
|
+
private fun languageDetectionConfidenceLevelToFloat(confidenceLevel: Int): Float =
|
|
590
|
+
when (confidenceLevel) {
|
|
591
|
+
SpeechRecognizer.LANGUAGE_DETECTION_CONFIDENCE_LEVEL_HIGHLY_CONFIDENT -> 1.0f
|
|
592
|
+
SpeechRecognizer.LANGUAGE_DETECTION_CONFIDENCE_LEVEL_CONFIDENT -> 0.8f
|
|
593
|
+
SpeechRecognizer.LANGUAGE_DETECTION_CONFIDENCE_LEVEL_NOT_CONFIDENT -> 0.5f
|
|
594
|
+
SpeechRecognizer.LANGUAGE_DETECTION_CONFIDENCE_LEVEL_UNKNOWN -> 0f
|
|
595
|
+
else -> 0.0f
|
|
596
|
+
}
|
|
597
|
+
|
|
584
598
|
override fun onResults(results: Bundle?) {
|
|
585
599
|
val resultsList = getResults(results)
|
|
586
600
|
|
|
@@ -614,6 +628,26 @@ class ExpoSpeechService(
|
|
|
614
628
|
}
|
|
615
629
|
}
|
|
616
630
|
|
|
631
|
+
override fun onLanguageDetection(results: Bundle) {
|
|
632
|
+
val detectedLanguage = results.getString(SpeechRecognizer.DETECTED_LANGUAGE)
|
|
633
|
+
val confidence = languageDetectionConfidenceLevelToFloat(results.getInt(SpeechRecognizer.LANGUAGE_DETECTION_CONFIDENCE_LEVEL))
|
|
634
|
+
|
|
635
|
+
// Only send event if language or confidence has changed
|
|
636
|
+
if (detectedLanguage != lastDetectedLanguage || confidence != lastLanguageConfidence) {
|
|
637
|
+
lastDetectedLanguage = detectedLanguage
|
|
638
|
+
lastLanguageConfidence = confidence
|
|
639
|
+
|
|
640
|
+
sendEvent(
|
|
641
|
+
"languagedetection",
|
|
642
|
+
mapOf(
|
|
643
|
+
"detectedLanguage" to detectedLanguage,
|
|
644
|
+
"confidence" to confidence,
|
|
645
|
+
"topLocaleAlternatives" to results.getStringArrayList(SpeechRecognizer.TOP_LOCALE_ALTERNATIVES),
|
|
646
|
+
),
|
|
647
|
+
)
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
617
651
|
/**
|
|
618
652
|
* For API 33: Basically same as onResults but doesn't stop
|
|
619
653
|
*/
|
|
@@ -70,6 +70,22 @@ export type ExpoSpeechRecognitionErrorEvent = {
|
|
|
70
70
|
error: ExpoSpeechRecognitionErrorCode;
|
|
71
71
|
message: string;
|
|
72
72
|
};
|
|
73
|
+
export type LanguageDetectionEvent = {
|
|
74
|
+
/** The language that was detected, in BCP-47 format. e.g. "en-US", "de-DE" */
|
|
75
|
+
detectedLanguage: string;
|
|
76
|
+
/** The confidence of the detected language. A value ranging between 0.0 and 1.0.
|
|
77
|
+
*
|
|
78
|
+
* Values range from:
|
|
79
|
+
*
|
|
80
|
+
* - 1.0 (highly confident)
|
|
81
|
+
* - 0.8 (confident)
|
|
82
|
+
* - 0.5 (not confident)
|
|
83
|
+
* - 0.0 (unknown)
|
|
84
|
+
*/
|
|
85
|
+
confidence: number;
|
|
86
|
+
/** The alternative locales for the same language, in BCP-47 format. e.g. ["en-US", "en-GB"] */
|
|
87
|
+
topLocaleAlternatives: string[];
|
|
88
|
+
};
|
|
73
89
|
/**
|
|
74
90
|
* Events that are dispatched from the native side
|
|
75
91
|
*/
|
|
@@ -109,6 +125,7 @@ export type ExpoSpeechRecognitionNativeEventMap = {
|
|
|
109
125
|
end: null;
|
|
110
126
|
soundstart: null;
|
|
111
127
|
soundend: null;
|
|
128
|
+
languagedetection: LanguageDetectionEvent;
|
|
112
129
|
volumechange: {
|
|
113
130
|
/**
|
|
114
131
|
* A float value between -2 and 10 indicating the volume of the input audio
|
|
@@ -152,7 +169,9 @@ export type ExpoSpeechRecognitionOptions = {
|
|
|
152
169
|
/**
|
|
153
170
|
* [Default: false] Include punctuation in the recognition results. This applies to full stops and commas.
|
|
154
171
|
*
|
|
155
|
-
* On Android, this configures [`EXTRA_ENABLE_FORMATTING`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING) in the recognizer intent (API level 33+).
|
|
172
|
+
* 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+).
|
|
173
|
+
*
|
|
174
|
+
* 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)
|
|
156
175
|
*
|
|
157
176
|
* On iOS, this configures [`SFSpeechRecognitionRequest.addsPunctuation`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/3930023-addspunctuation).
|
|
158
177
|
*/
|
|
@@ -337,6 +356,15 @@ export type AndroidIntentOptions = {
|
|
|
337
356
|
* Depending on the recognizer implementation, this value may have no effect.
|
|
338
357
|
*/
|
|
339
358
|
EXTRA_ENABLE_LANGUAGE_SWITCH: (typeof RecognizerIntentEnableLanguageSwitch)[keyof typeof RecognizerIntentEnableLanguageSwitch];
|
|
359
|
+
/**
|
|
360
|
+
* https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING
|
|
361
|
+
*
|
|
362
|
+
* NOTE: This is also configurable through `addsPunctuation` (which sets `EXTRA_ENABLE_FORMATTING` to "quality")
|
|
363
|
+
*
|
|
364
|
+
* [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.
|
|
365
|
+
*
|
|
366
|
+
*/
|
|
367
|
+
EXTRA_ENABLE_FORMATTING: "latency" | "quality";
|
|
340
368
|
/**
|
|
341
369
|
* https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION
|
|
342
370
|
*
|
|
@@ -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,cAAc,CAAC;AAEjD,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,MAAM,MAAM,kCAAkC,GAAG;IAC/C,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,qHAAqH;IACrH,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,6EAA6E;AAC7E,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,2BAA2B,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,8BAA8B;AACxC,6DAA6D;AAC3D,SAAS;AACX,6BAA6B;GAC3B,eAAe;AACjB,kJAAkJ;GAChJ,aAAa;AACf,wDAAwD;GACtD,wBAAwB;AAC1B,4EAA4E;GAC1E,SAAS;AACX,oCAAoC;G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;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC
|
|
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,cAAc,CAAC;AAEjD,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,MAAM,MAAM,kCAAkC,GAAG;IAC/C,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,aAAa,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,qHAAqH;IACrH,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,6EAA6E;AAC7E,MAAM,MAAM,gCAAgC,GAAG;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,2BAA2B,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,8BAA8B;AACxC,6DAA6D;AAC3D,SAAS;AACX,6BAA6B;GAC3B,eAAe;AACjB,kJAAkJ;GAChJ,aAAa;AACf,wDAAwD;GACtD,wBAAwB;AAC1B,4EAA4E;GAC1E,SAAS;AACX,oCAAoC;GACl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AIG;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 \"react-native\";\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\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 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 (API level 33+).\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_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 interface ExpoSpeechRecognitionModuleType extends NativeModule {\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 \"react-native\";\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 interface ExpoSpeechRecognitionModuleType extends NativeModule {\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"]}
|
|
@@ -94,6 +94,8 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
94
94
|
"start",
|
|
95
95
|
// Called when there's results (as a string array, not API compliant)
|
|
96
96
|
"result",
|
|
97
|
+
// Called when the language detection (and switching) results are available.
|
|
98
|
+
"languagedetection",
|
|
97
99
|
// Fired when the input volume changes
|
|
98
100
|
"volumechange"
|
|
99
101
|
)
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-speech-recognition",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.25",
|
|
4
4
|
"description": "Speech Recognition for React Native Expo projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "expo-module build",
|
|
9
12
|
"clean": "expo-module clean",
|
|
@@ -14,6 +17,7 @@
|
|
|
14
17
|
"expo-module": "expo-module",
|
|
15
18
|
"open:ios": "open -a \"Xcode\" example/ios",
|
|
16
19
|
"open:android": "open -a \"Android Studio\" example/android",
|
|
20
|
+
"release": "npm run prepare && changeset publish",
|
|
17
21
|
"ts:check": "tsc -p . --noEmit"
|
|
18
22
|
},
|
|
19
23
|
"keywords": [
|
|
@@ -32,6 +36,7 @@
|
|
|
32
36
|
"license": "MIT",
|
|
33
37
|
"homepage": "https://github.com/jamsch/expo-speech-recognition#readme",
|
|
34
38
|
"devDependencies": {
|
|
39
|
+
"@changesets/cli": "^2.27.9",
|
|
35
40
|
"@types/dom-speech-recognition": "^0.0.4",
|
|
36
41
|
"@types/react": "^18.3.3",
|
|
37
42
|
"expo-module-scripts": "^3.5.2",
|
|
@@ -88,6 +88,23 @@ export type ExpoSpeechRecognitionErrorEvent = {
|
|
|
88
88
|
message: string;
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
+
export type LanguageDetectionEvent = {
|
|
92
|
+
/** The language that was detected, in BCP-47 format. e.g. "en-US", "de-DE" */
|
|
93
|
+
detectedLanguage: string;
|
|
94
|
+
/** The confidence of the detected language. A value ranging between 0.0 and 1.0.
|
|
95
|
+
*
|
|
96
|
+
* Values range from:
|
|
97
|
+
*
|
|
98
|
+
* - 1.0 (highly confident)
|
|
99
|
+
* - 0.8 (confident)
|
|
100
|
+
* - 0.5 (not confident)
|
|
101
|
+
* - 0.0 (unknown)
|
|
102
|
+
*/
|
|
103
|
+
confidence: number;
|
|
104
|
+
/** The alternative locales for the same language, in BCP-47 format. e.g. ["en-US", "en-GB"] */
|
|
105
|
+
topLocaleAlternatives: string[];
|
|
106
|
+
};
|
|
107
|
+
|
|
91
108
|
/**
|
|
92
109
|
* Events that are dispatched from the native side
|
|
93
110
|
*/
|
|
@@ -127,6 +144,7 @@ export type ExpoSpeechRecognitionNativeEventMap = {
|
|
|
127
144
|
end: null;
|
|
128
145
|
soundstart: null;
|
|
129
146
|
soundend: null;
|
|
147
|
+
languagedetection: LanguageDetectionEvent;
|
|
130
148
|
volumechange: {
|
|
131
149
|
/**
|
|
132
150
|
* A float value between -2 and 10 indicating the volume of the input audio
|
|
@@ -171,7 +189,9 @@ export type ExpoSpeechRecognitionOptions = {
|
|
|
171
189
|
/**
|
|
172
190
|
* [Default: false] Include punctuation in the recognition results. This applies to full stops and commas.
|
|
173
191
|
*
|
|
174
|
-
* On Android, this configures [`EXTRA_ENABLE_FORMATTING`](https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING) in the recognizer intent (API level 33+).
|
|
192
|
+
* 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+).
|
|
193
|
+
*
|
|
194
|
+
* 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)
|
|
175
195
|
*
|
|
176
196
|
* On iOS, this configures [`SFSpeechRecognitionRequest.addsPunctuation`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/3930023-addspunctuation).
|
|
177
197
|
*/
|
|
@@ -372,6 +392,15 @@ export type AndroidIntentOptions = {
|
|
|
372
392
|
* Depending on the recognizer implementation, this value may have no effect.
|
|
373
393
|
*/
|
|
374
394
|
EXTRA_ENABLE_LANGUAGE_SWITCH: (typeof RecognizerIntentEnableLanguageSwitch)[keyof typeof RecognizerIntentEnableLanguageSwitch];
|
|
395
|
+
/**
|
|
396
|
+
* https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_ENABLE_FORMATTING
|
|
397
|
+
*
|
|
398
|
+
* NOTE: This is also configurable through `addsPunctuation` (which sets `EXTRA_ENABLE_FORMATTING` to "quality")
|
|
399
|
+
*
|
|
400
|
+
* [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.
|
|
401
|
+
*
|
|
402
|
+
*/
|
|
403
|
+
EXTRA_ENABLE_FORMATTING: "latency" | "quality";
|
|
375
404
|
/**
|
|
376
405
|
* https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_HIDE_PARTIAL_TRAILING_PUNCTUATION
|
|
377
406
|
*
|