expo-speech-recognition 2.1.5 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,127 @@
1
1
  # expo-speech-recognition
2
2
 
3
+ ## 3.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 7a64d6e: (iOS) Allow passing through folder URIs for audio persistence.
8
+
9
+ You can now do the following on Android and iOS:
10
+
11
+ ```ts
12
+ import { ExpoSpeechRecognitionModule } from "expo-speech-recognition";
13
+ import { Directory, Paths } from "expo-file-system";
14
+
15
+ const outputDirectory = new Directory(Paths.join(Paths.cache, "recordings"));
16
+
17
+ // Create the folder, if it doesn't exist yet (Android does not yet create intermediates)
18
+ outputDirectory.create({ intermediates: true, idempotent: true });
19
+
20
+ // Start speech recognition with a custom directory
21
+ ExpoSpeechRecognitionModule.start({
22
+ lang: "en-US",
23
+ recordingOptions: {
24
+ persist: true,
25
+ // e.g. "file:///data/user/0/com.yourapp.app/cache/recordings/"
26
+ outputDirectory: outputDirectory.uri,
27
+ },
28
+ });
29
+ ```
30
+
31
+ ## 3.0.0
32
+
33
+ ### Major Changes
34
+
35
+ - 3b48113: With this major version change, we've removed some top-level exports from the base `expo-speech-recognition` library.
36
+ Instead you'll now need to call the function directly from `ExpoSpeechRecognitionModule`. This was changed to address
37
+ issues with regards to symbol bindings.
38
+
39
+ The list of removed exports:
40
+
41
+ ```ts
42
+ // Removed
43
+ import { getSupportedLocales } from "expo-speech-recognition";
44
+ // Instead use:
45
+ ExpoSpeechRecognitionModule.getSupportedLocales();
46
+ ```
47
+
48
+ ```ts
49
+ // Removed
50
+ import { getSpeechRecognitionServices } from "expo-speech-recognition";
51
+ // Instead use:
52
+ ExpoSpeechRecognitionModule.getSpeechRecognitionServices();
53
+ ```
54
+
55
+ ```ts
56
+ // Removed
57
+ import { supportsOnDeviceRecognition } from "expo-speech-recognition";
58
+ // Instead use:
59
+ ExpoSpeechRecognitionModule.supportsOnDeviceRecognition();
60
+ ```
61
+
62
+ ```ts
63
+ // Removed
64
+ import { supportsRecording } from "expo-speech-recognition";
65
+ // Instead use:
66
+ ExpoSpeechRecognitionModule.supportsRecording();
67
+ ```
68
+
69
+ ```ts
70
+ // Removed
71
+ import { setCategoryIOS } from "expo-speech-recognition";
72
+ // Instead use:
73
+ ExpoSpeechRecognitionModule.setCategoryIOS({ ... });
74
+ ```
75
+
76
+ ```ts
77
+ // Removed
78
+ import { getAudioSessionCategoryAndOptionsIOS } from "expo-speech-recognition";
79
+ // Instead use:
80
+ ExpoSpeechRecognitionModule.getAudioSessionCategoryAndOptionsIOS();
81
+ ```
82
+
83
+ ```ts
84
+ // Removed
85
+ import { setAudioSessionActiveIOS } from "expo-speech-recognition";
86
+ // Instead use:
87
+ ExpoSpeechRecognitionModule.setAudioSessionActiveIOS(true, { ... });
88
+ ```
89
+
90
+ ```ts
91
+ // Removed
92
+ import { androidTriggerOfflineModelDownload } from "expo-speech-recognition";
93
+ // Instead use:
94
+ ExpoSpeechRecognitionModule.androidTriggerOfflineModelDownload({ ... });
95
+ ```
96
+
97
+ ```ts
98
+ // Removed
99
+ import { isRecognitionAvailable } from "expo-speech-recognition";
100
+ // Instead use:
101
+ ExpoSpeechRecognitionModule.isRecognitionAvailable();
102
+ ```
103
+
104
+ ```ts
105
+ // Removed
106
+ import { getDefaultRecognitionService } from "expo-speech-recognition";
107
+ // Instead use:
108
+ ExpoSpeechRecognitionModule.getDefaultRecognitionService();
109
+ ```
110
+
111
+ ```ts
112
+ // Removed
113
+ import { getAssistantService } from "expo-speech-recognition";
114
+ // Instead use:
115
+ ExpoSpeechRecognitionModule.getAssistantService();
116
+ ```
117
+
118
+ ```ts
119
+ // Removed
120
+ import { addSpeechRecognitionListener } from "expo-speech-recognition";
121
+ // Instead use:
122
+ ExpoSpeechRecognitionModule.addListener("foo", (event) => { ... });
123
+ ```
124
+
3
125
  ## 2.1.5
4
126
 
5
127
  ### Patch Changes
package/README.md CHANGED
@@ -294,9 +294,9 @@ ExpoSpeechRecognitionModule.start({
294
294
  recordingOptions: {
295
295
  // [Default: false] Whether to persist the audio to a local file path.
296
296
  persist: false,
297
- // [Default: FileSystem.CacheDirectory]
297
+ // [Default: Paths.cache.uri]
298
298
  // Changes the default storage location for the audio file.
299
- // e.g. `FileSystem.documentDirectory` (from `expo-file-system`)
299
+ // e.g. `Paths.document.uri` (from `expo-file-system`)
300
300
  outputDirectory: undefined,
301
301
  // [Default: `"recording_${timestamp|uuid}.[wav|caf]"`]
302
302
  // Changes the file name for the audio file.
@@ -458,7 +458,7 @@ function RecordAudio() {
458
458
  recordingOptions: {
459
459
  persist: true,
460
460
  // Optional: Specify the output file path to save the recording to
461
- // e.g. `FileSystem.documentDirectory` (from `expo-file-system`)
461
+ // e.g. `Paths.document.uri` (from `expo-file-system`)
462
462
  outputDirectory:
463
463
  "/data/user/0/expo.modules.speechrecognition.example/files",
464
464
  // Optional: Specify the output file name to save the recording to
@@ -25,6 +25,8 @@ import expo.modules.kotlin.modules.Module
25
25
  import expo.modules.kotlin.modules.ModuleDefinition
26
26
  import java.util.concurrent.Executors
27
27
 
28
+ private const val TAG = "ESRModule"
29
+
28
30
  class ExpoSpeechRecognitionModule : Module() {
29
31
  private val expoSpeechService by lazy {
30
32
  ExpoSpeechService(appContext.reactContext!!) { name, body ->
@@ -34,7 +36,7 @@ class ExpoSpeechRecognitionModule : Module() {
34
36
  } catch (e: IllegalArgumentException) {
35
37
  // "Cannot create an event emitter for the module that isn't present in the module registry."
36
38
  // Likely can occur after destroying the module
37
- Log.e("ExpoSpeechRecognitionModule", "Failed to send event: $name", e)
39
+ Log.e(TAG, "Failed to send event: $name", e)
38
40
  }
39
41
  }
40
42
  }
@@ -42,6 +44,7 @@ class ExpoSpeechRecognitionModule : Module() {
42
44
  // Each module class must implement the definition function. The definition consists of components
43
45
  // that describes the module's functionality and behavior.
44
46
  // See https://docs.expo.dev/modules/module-api for more details about available components.
47
+ @RequiresApi(Build.VERSION_CODES.FROYO)
45
48
  override fun definition() =
46
49
  ModuleDefinition {
47
50
  // Sets the name of the module that JavaScript code will use to refer to the module. Takes a
@@ -162,7 +165,7 @@ class ExpoSpeechRecognitionModule : Module() {
162
165
  }
163
166
 
164
167
  AsyncFunction("getSpeechRecognizerPermissionsAsync") { promise: Promise ->
165
- Log.w("ExpoSpeechRecognitionModule", "getSpeechRecognizerPermissionsAsync is not supported on Android. Returning a granted permission response.")
168
+ Log.w(TAG, "getSpeechRecognizerPermissionsAsync is not supported on Android. Returning a granted permission response.")
166
169
  promise.resolve(
167
170
  Bundle().apply {
168
171
  putString(PermissionsResponse.EXPIRES_KEY, "never")
@@ -174,7 +177,7 @@ class ExpoSpeechRecognitionModule : Module() {
174
177
  }
175
178
 
176
179
  AsyncFunction("requestSpeechRecognizerPermissionsAsync") { promise: Promise ->
177
- Log.w("ExpoSpeechRecognitionModule", "requestSpeechRecognizerPermissionsAsync is not supported on Android. Returning a granted permission response.")
180
+ Log.w(TAG, "requestSpeechRecognizerPermissionsAsync is not supported on Android. Returning a granted permission response.")
178
181
  promise.resolve(
179
182
  Bundle().apply {
180
183
  putString(PermissionsResponse.EXPIRES_KEY, "never")
@@ -347,6 +350,7 @@ class ExpoSpeechRecognitionModule : Module() {
347
350
 
348
351
  private fun hasNotGrantedRecordPermissions(): Boolean = appContext.permissions?.hasGrantedPermissions(RECORD_AUDIO)?.not() ?: false
349
352
 
353
+ @RequiresApi(Build.VERSION_CODES.CUPCAKE)
350
354
  private fun getDefaultAssistantService(): ComponentName? {
351
355
  val contentResolver = appContext.reactContext?.contentResolver ?: return null
352
356
  val defaultAssistant = Settings.Secure.getString(contentResolver, "assistant")
@@ -356,6 +360,7 @@ class ExpoSpeechRecognitionModule : Module() {
356
360
  return ComponentName.unflattenFromString(defaultAssistant)
357
361
  }
358
362
 
363
+ @RequiresApi(Build.VERSION_CODES.CUPCAKE)
359
364
  private fun getDefaultVoiceRecognitionService(): ComponentName? {
360
365
  val contentResolver = appContext.reactContext?.contentResolver ?: return null
361
366
  val defaultVoiceRecognitionService = Settings.Secure.getString(contentResolver, "voice_recognition_service")
package/build/index.d.ts CHANGED
@@ -2,37 +2,5 @@ export { ExpoWebSpeechRecognition, ExpoWebSpeechGrammar, ExpoWebSpeechGrammarLis
2
2
  export { ExpoSpeechRecognitionModule } from "./ExpoSpeechRecognitionModule";
3
3
  export { useSpeechRecognitionEvent } from "./useSpeechRecognitionEvent";
4
4
  export { AVAudioSessionCategory, AVAudioSessionCategoryOptions, AVAudioSessionMode, RecognizerIntentExtraLanguageModel, RecognizerIntentEnableLanguageSwitch, AudioEncodingAndroid, TaskHintIOS, SpeechRecognizerErrorAndroid, } from "./constants";
5
- export declare const getSupportedLocales: (options?: {
6
- androidRecognitionServicePackage?: string;
7
- }) => Promise<{
8
- locales: string[];
9
- installedLocales: string[];
10
- }>;
11
- export declare const getSpeechRecognitionServices: () => string[];
12
- export declare const supportsOnDeviceRecognition: () => boolean;
13
- export declare const supportsRecording: () => boolean;
14
- export declare const setCategoryIOS: (options: import("./ExpoSpeechRecognitionModule.types").SetCategoryOptions) => void;
15
- export declare const getAudioSessionCategoryAndOptionsIOS: () => {
16
- category: import("./ExpoSpeechRecognitionModule.types").AVAudioSessionCategoryValue;
17
- categoryOptions: import("./ExpoSpeechRecognitionModule.types").AVAudioSessionCategoryOptionsValue[];
18
- mode: import("./ExpoSpeechRecognitionModule.types").AVAudioSessionModeValue;
19
- };
20
- export declare const setAudioSessionActiveIOS: (value: boolean, options?: {
21
- notifyOthersOnDeactivation: boolean;
22
- }) => void;
23
- export declare const androidTriggerOfflineModelDownload: (options: {
24
- locale: string;
25
- }) => Promise<{
26
- status: "download_success" | "opened_dialog" | "download_canceled";
27
- message: string;
28
- }>;
29
- export declare const isRecognitionAvailable: () => boolean;
30
- export declare const getDefaultRecognitionService: () => {
31
- packageName: string;
32
- };
33
- export declare const getAssistantService: () => {
34
- packageName: string;
35
- };
36
- export declare const addSpeechRecognitionListener: <EventName extends keyof import("./ExpoSpeechRecognitionModule.types").ExpoSpeechRecognitionNativeEventMap>(eventName: EventName, listener: import("./ExpoSpeechRecognitionModule.types").ExpoSpeechRecognitionNativeEvents[EventName]) => import("expo-modules-core/build/ts-declarations/EventEmitter").EventSubscription;
37
5
  export type { ExpoSpeechRecognitionOptions, AndroidIntentOptions, ExpoSpeechRecognitionNativeEventMap, AVAudioSessionCategoryOptionsValue, AVAudioSessionModeValue, AVAudioSessionCategoryValue, AudioEncodingAndroidValue, AudioSourceOptions, RecordingOptions, IOSTaskHintValue, SetCategoryOptions, ExpoSpeechRecognitionErrorCode, ExpoSpeechRecognitionErrorEvent, ExpoSpeechRecognitionResultEvent, ExpoSpeechRecognitionResult, ExpoSpeechRecognitionResultSegment, } from "./ExpoSpeechRecognitionModule.types";
38
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAG5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,kCAAkC,EAClC,oCAAoC,EACpC,oBAAoB,EACpB,WAAW,EACX,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,mBAAmB,GAAI,UAAU;IAC5C,gCAAgC,CAAC,EAAE,MAAM,CAAC;CAC3C;;;EAAmE,CAAC;AAErE,eAAO,MAAM,4BAA4B,gBACiB,CAAC;AAE3D,eAAO,MAAM,2BAA2B,eACiB,CAAC;AAE1D,eAAO,MAAM,iBAAiB,eAAgD,CAAC;AAE/E,eAAO,MAAM,cAAc,qFAA6C,CAAC;AAEzE,eAAO,MAAM,oCAAoC;;;;CACiB,CAAC;AAEnE,eAAO,MAAM,wBAAwB;;UACiB,CAAC;AAEvD,eAAO,MAAM,kCAAkC;;;;;EACiB,CAAC;AAEjE,eAAO,MAAM,sBAAsB,eACiB,CAAC;AAErD,eAAO,MAAM,4BAA4B;;CACiB,CAAC;AAE3D,eAAO,MAAM,mBAAmB;;CACiB,CAAC;AAElD,eAAO,MAAM,4BAA4B,6TACA,CAAC;AAE1C,YAAY,EACV,4BAA4B,EAC5B,oBAAoB,EACpB,mCAAmC,EACnC,kCAAkC,EAClC,uBAAuB,EACvB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,EAChC,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,qCAAqC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAG5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,kCAAkC,EAClC,oCAAoC,EACpC,oBAAoB,EACpB,WAAW,EACX,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,4BAA4B,EAC5B,oBAAoB,EACpB,mCAAmC,EACnC,kCAAkC,EAClC,uBAAuB,EACvB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,EAChC,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,qCAAqC,CAAC"}
package/build/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import { ExpoSpeechRecognitionModule } from "./ExpoSpeechRecognitionModule";
2
1
  // Export the SpeechRecognition APIs
3
2
  export { ExpoWebSpeechRecognition, ExpoWebSpeechGrammar, ExpoWebSpeechGrammarList, } from "./ExpoWebSpeechRecognition";
4
3
  // Native module
@@ -7,16 +6,4 @@ export { ExpoSpeechRecognitionModule } from "./ExpoSpeechRecognitionModule";
7
6
  export { useSpeechRecognitionEvent } from "./useSpeechRecognitionEvent";
8
7
  // Constants
9
8
  export { AVAudioSessionCategory, AVAudioSessionCategoryOptions, AVAudioSessionMode, RecognizerIntentExtraLanguageModel, RecognizerIntentEnableLanguageSwitch, AudioEncodingAndroid, TaskHintIOS, SpeechRecognizerErrorAndroid, } from "./constants";
10
- export const getSupportedLocales = (options) => ExpoSpeechRecognitionModule.getSupportedLocales(options ?? {});
11
- export const getSpeechRecognitionServices = ExpoSpeechRecognitionModule.getSpeechRecognitionServices;
12
- export const supportsOnDeviceRecognition = ExpoSpeechRecognitionModule.supportsOnDeviceRecognition;
13
- export const supportsRecording = ExpoSpeechRecognitionModule.supportsRecording;
14
- export const setCategoryIOS = ExpoSpeechRecognitionModule.setCategoryIOS;
15
- export const getAudioSessionCategoryAndOptionsIOS = ExpoSpeechRecognitionModule.getAudioSessionCategoryAndOptionsIOS;
16
- export const setAudioSessionActiveIOS = ExpoSpeechRecognitionModule.setAudioSessionActiveIOS;
17
- export const androidTriggerOfflineModelDownload = ExpoSpeechRecognitionModule.androidTriggerOfflineModelDownload;
18
- export const isRecognitionAvailable = ExpoSpeechRecognitionModule.isRecognitionAvailable;
19
- export const getDefaultRecognitionService = ExpoSpeechRecognitionModule.getDefaultRecognitionService;
20
- export const getAssistantService = ExpoSpeechRecognitionModule.getAssistantService;
21
- export const addSpeechRecognitionListener = ExpoSpeechRecognitionModule.addListener;
22
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,oCAAoC;AACpC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAEpC,gBAAgB;AAChB,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,QAAQ;AACR,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,YAAY;AACZ,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,kCAAkC,EAClC,oCAAoC,EACpC,oBAAoB,EACpB,WAAW,EACX,4BAA4B,GAC7B,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAEnC,EAAE,EAAE,CAAC,2BAA2B,CAAC,mBAAmB,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,4BAA4B,GACvC,2BAA2B,CAAC,4BAA4B,CAAC;AAE3D,MAAM,CAAC,MAAM,2BAA2B,GACtC,2BAA2B,CAAC,2BAA2B,CAAC;AAE1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,2BAA2B,CAAC,iBAAiB,CAAC;AAE/E,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,CAAC,cAAc,CAAC;AAEzE,MAAM,CAAC,MAAM,oCAAoC,GAC/C,2BAA2B,CAAC,oCAAoC,CAAC;AAEnE,MAAM,CAAC,MAAM,wBAAwB,GACnC,2BAA2B,CAAC,wBAAwB,CAAC;AAEvD,MAAM,CAAC,MAAM,kCAAkC,GAC7C,2BAA2B,CAAC,kCAAkC,CAAC;AAEjE,MAAM,CAAC,MAAM,sBAAsB,GACjC,2BAA2B,CAAC,sBAAsB,CAAC;AAErD,MAAM,CAAC,MAAM,4BAA4B,GACvC,2BAA2B,CAAC,4BAA4B,CAAC;AAE3D,MAAM,CAAC,MAAM,mBAAmB,GAC9B,2BAA2B,CAAC,mBAAmB,CAAC;AAElD,MAAM,CAAC,MAAM,4BAA4B,GACvC,2BAA2B,CAAC,WAAW,CAAC","sourcesContent":["import { ExpoSpeechRecognitionModule } from \"./ExpoSpeechRecognitionModule\";\n\n// Export the SpeechRecognition APIs\nexport {\n ExpoWebSpeechRecognition,\n ExpoWebSpeechGrammar,\n ExpoWebSpeechGrammarList,\n} from \"./ExpoWebSpeechRecognition\";\n\n// Native module\nexport { ExpoSpeechRecognitionModule } from \"./ExpoSpeechRecognitionModule\";\n\n// Hooks\nexport { useSpeechRecognitionEvent } from \"./useSpeechRecognitionEvent\";\n\n// Constants\nexport {\n AVAudioSessionCategory,\n AVAudioSessionCategoryOptions,\n AVAudioSessionMode,\n RecognizerIntentExtraLanguageModel,\n RecognizerIntentEnableLanguageSwitch,\n AudioEncodingAndroid,\n TaskHintIOS,\n SpeechRecognizerErrorAndroid,\n} from \"./constants\";\n\nexport const getSupportedLocales = (options?: {\n androidRecognitionServicePackage?: string;\n}) => ExpoSpeechRecognitionModule.getSupportedLocales(options ?? {});\n\nexport const getSpeechRecognitionServices =\n ExpoSpeechRecognitionModule.getSpeechRecognitionServices;\n\nexport const supportsOnDeviceRecognition =\n ExpoSpeechRecognitionModule.supportsOnDeviceRecognition;\n\nexport const supportsRecording = ExpoSpeechRecognitionModule.supportsRecording;\n\nexport const setCategoryIOS = ExpoSpeechRecognitionModule.setCategoryIOS;\n\nexport const getAudioSessionCategoryAndOptionsIOS =\n ExpoSpeechRecognitionModule.getAudioSessionCategoryAndOptionsIOS;\n\nexport const setAudioSessionActiveIOS =\n ExpoSpeechRecognitionModule.setAudioSessionActiveIOS;\n\nexport const androidTriggerOfflineModelDownload =\n ExpoSpeechRecognitionModule.androidTriggerOfflineModelDownload;\n\nexport const isRecognitionAvailable =\n ExpoSpeechRecognitionModule.isRecognitionAvailable;\n\nexport const getDefaultRecognitionService =\n ExpoSpeechRecognitionModule.getDefaultRecognitionService;\n\nexport const getAssistantService =\n ExpoSpeechRecognitionModule.getAssistantService;\n\nexport const addSpeechRecognitionListener =\n ExpoSpeechRecognitionModule.addListener;\n\nexport type {\n ExpoSpeechRecognitionOptions,\n AndroidIntentOptions,\n ExpoSpeechRecognitionNativeEventMap,\n AVAudioSessionCategoryOptionsValue,\n AVAudioSessionModeValue,\n AVAudioSessionCategoryValue,\n AudioEncodingAndroidValue,\n AudioSourceOptions,\n RecordingOptions,\n IOSTaskHintValue,\n SetCategoryOptions,\n ExpoSpeechRecognitionErrorCode,\n ExpoSpeechRecognitionErrorEvent,\n ExpoSpeechRecognitionResultEvent,\n ExpoSpeechRecognitionResult,\n ExpoSpeechRecognitionResultSegment,\n} from \"./ExpoSpeechRecognitionModule.types\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAEpC,gBAAgB;AAChB,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,QAAQ;AACR,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,YAAY;AACZ,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,kCAAkC,EAClC,oCAAoC,EACpC,oBAAoB,EACpB,WAAW,EACX,4BAA4B,GAC7B,MAAM,aAAa,CAAC","sourcesContent":["// Export the SpeechRecognition APIs\nexport {\n ExpoWebSpeechRecognition,\n ExpoWebSpeechGrammar,\n ExpoWebSpeechGrammarList,\n} from \"./ExpoWebSpeechRecognition\";\n\n// Native module\nexport { ExpoSpeechRecognitionModule } from \"./ExpoSpeechRecognitionModule\";\n\n// Hooks\nexport { useSpeechRecognitionEvent } from \"./useSpeechRecognitionEvent\";\n\n// Constants\nexport {\n AVAudioSessionCategory,\n AVAudioSessionCategoryOptions,\n AVAudioSessionMode,\n RecognizerIntentExtraLanguageModel,\n RecognizerIntentEnableLanguageSwitch,\n AudioEncodingAndroid,\n TaskHintIOS,\n SpeechRecognizerErrorAndroid,\n} from \"./constants\";\n\nexport type {\n ExpoSpeechRecognitionOptions,\n AndroidIntentOptions,\n ExpoSpeechRecognitionNativeEventMap,\n AVAudioSessionCategoryOptionsValue,\n AVAudioSessionModeValue,\n AVAudioSessionCategoryValue,\n AudioEncodingAndroidValue,\n AudioSourceOptions,\n RecordingOptions,\n IOSTaskHintValue,\n SetCategoryOptions,\n ExpoSpeechRecognitionErrorCode,\n ExpoSpeechRecognitionErrorEvent,\n ExpoSpeechRecognitionResultEvent,\n ExpoSpeechRecognitionResult,\n ExpoSpeechRecognitionResultSegment,\n} from \"./ExpoSpeechRecognitionModule.types\";\n"]}
package/eslint.config.mjs CHANGED
@@ -6,9 +6,11 @@ import tseslint from "typescript-eslint";
6
6
  export default tseslint.config([
7
7
  tseslint.configs.recommended,
8
8
  js.configs.recommended,
9
+ {
10
+ ignores: ["build/**", "app.plugin.js", "example/**"],
11
+ },
9
12
  {
10
13
  files: ["src/**/*.{js,jsx,ts,tsx}"],
11
- ignores: ["build/**"],
12
14
  languageOptions: {
13
15
  globals: globals.node,
14
16
  },
@@ -236,16 +236,16 @@ public class ExpoSpeechRecognitionModule: Module {
236
236
  },
237
237
  audioStartHandler: { [weak self] filePath in
238
238
  if let filePath: String {
239
- // "file:///Users/..../Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.wav"
240
- self?.sendEvent("audiostart", ["uri": "file://" + filePath])
239
+ let uri = filePath.hasPrefix("file://") ? filePath : "file://" + filePath
240
+ self?.sendEvent("audiostart", ["uri": uri])
241
241
  } else {
242
242
  self?.sendEvent("audiostart", ["uri": nil])
243
243
  }
244
244
  },
245
245
  audioEndHandler: { [weak self] filePath in
246
246
  if let filePath: String {
247
- // "file:///Users/..../Library/Caches/audio_CD5E6C6C-3D9D-4754-9188-D6FAF97D9DF2.wav"
248
- self?.sendEvent("audioend", ["uri": "file://" + filePath])
247
+ let uri = filePath.hasPrefix("file://") ? filePath : "file://" + filePath
248
+ self?.sendEvent("audioend", ["uri": uri])
249
249
  } else {
250
250
  self?.sendEvent("audioend", ["uri": nil])
251
251
  }
@@ -239,7 +239,7 @@ actor ExpoSpeechRecognizer: ObservableObject {
239
239
  startHandler()
240
240
 
241
241
  // If user has opted in to recording, emit an "audiostart" event with the path
242
- audioStartHandler(outputFileUrl?.path)
242
+ audioStartHandler(outputFileUrl?.absoluteString)
243
243
  } catch {
244
244
  errorHandler(error)
245
245
  reset(andEmitEnd: true)
@@ -399,9 +399,14 @@ actor ExpoSpeechRecognizer: ObservableObject {
399
399
  let baseDir: URL
400
400
 
401
401
  if let outputDirectory = outputDirectory {
402
- baseDir = URL(fileURLWithPath: outputDirectory, isDirectory: true)
402
+ guard let resolvedURL = Self.resolveOutputDirectoryURL(outputDirectory) else {
403
+ print("expo-speech-recognition: ERROR - Invalid outputDirectory: \(outputDirectory)")
404
+ return nil
405
+ }
406
+ baseDir = resolvedURL
403
407
  } else {
404
- guard let dirPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first
408
+ guard
409
+ let dirPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first
405
410
  else {
406
411
  print("Failed to get cache directory path.")
407
412
  return nil
@@ -409,10 +414,20 @@ actor ExpoSpeechRecognizer: ObservableObject {
409
414
  baseDir = dirPath
410
415
  }
411
416
 
417
+ do {
418
+ try FileManager.default.createDirectory(
419
+ at: baseDir,
420
+ withIntermediateDirectories: true
421
+ )
422
+ } catch {
423
+ print("expo-speech-recognition: ERROR - Failed to create output directory: \(error)")
424
+ return nil
425
+ }
426
+
412
427
  let fileName = outputFileName ?? "recording_\(UUID().uuidString).wav"
413
428
  let filePath = baseDir.appendingPathComponent(fileName)
414
429
 
415
- _ = ExtAudioFileCreateWithURL(
430
+ let status = ExtAudioFileCreateWithURL(
416
431
  filePath as CFURL,
417
432
  kAudioFileWAVEType,
418
433
  audioFormat.streamDescription,
@@ -421,6 +436,12 @@ actor ExpoSpeechRecognizer: ObservableObject {
421
436
  &audioFileRef
422
437
  )
423
438
 
439
+ guard status == noErr else {
440
+ print("expo-speech-recognition: ERROR - Failed to create audio file: \(status)")
441
+ audioFileRef = nil
442
+ return nil
443
+ }
444
+
424
445
  // Note: using `AVAudioFile()` doesn't seem to work
425
446
  // when downsampling pcmFloat32 to pcmInt16
426
447
 
@@ -432,13 +453,29 @@ actor ExpoSpeechRecognizer: ObservableObject {
432
453
  return filePath
433
454
  }
434
455
 
456
+ private static func resolveOutputDirectoryURL(_ directory: String) -> URL? {
457
+ if let url = URL(string: directory.trimmingCharacters(in: .whitespacesAndNewlines)),
458
+ let scheme = url.scheme,
459
+ !scheme.isEmpty
460
+ {
461
+ guard url.isFileURL else {
462
+ print("expo-speech-recognition: ERROR - Output directory must be a file URL.")
463
+ return nil
464
+ }
465
+ return url.hasDirectoryPath ? url : url.appendingPathComponent("")
466
+ }
467
+
468
+ let expandedDirectory = (directory as NSString).expandingTildeInPath
469
+ return URL(fileURLWithPath: expandedDirectory, isDirectory: true)
470
+ }
471
+
435
472
  private func handleSpeechStart() {
436
473
  speechStartHandler?()
437
474
  speechStartHandler = nil
438
475
  }
439
476
 
440
477
  private func end() {
441
- let filePath = self.outputFileUrl?.path
478
+ let filePath = self.outputFileUrl?.absoluteString
442
479
  outputFileUrl = nil
443
480
  Task {
444
481
  await MainActor.run {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-speech-recognition",
3
- "version": "2.1.5",
3
+ "version": "3.0.1",
4
4
  "description": "Speech Recognition for React Native Expo projects",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -40,14 +40,14 @@
40
40
  "license": "MIT",
41
41
  "homepage": "https://github.com/jamsch/expo-speech-recognition#readme",
42
42
  "devDependencies": {
43
- "@changesets/cli": "^2.29.2",
44
- "@types/dom-speech-recognition": "^0.0.6",
45
- "@types/react": "~19.0.14",
46
- "expo": "~53.0.0",
47
- "expo-module-scripts": "^4.1.6",
48
- "globals": "16.2.0",
49
- "typescript": "~5.8.3",
50
- "typescript-eslint": "8.33.1"
43
+ "@changesets/cli": "^2.29.7",
44
+ "@types/dom-speech-recognition": "^0.0.7",
45
+ "@types/react": "~19.1.15",
46
+ "expo": "~54.0.0",
47
+ "expo-module-scripts": "^5.0.7",
48
+ "globals": "16.4.0",
49
+ "typescript": "~5.9.3",
50
+ "typescript-eslint": "8.46.3"
51
51
  },
52
52
  "prettier": {
53
53
  "trailingComma": "all"
package/src/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { ExpoSpeechRecognitionModule } from "./ExpoSpeechRecognitionModule";
2
-
3
1
  // Export the SpeechRecognition APIs
4
2
  export {
5
3
  ExpoWebSpeechRecognition,
@@ -25,41 +23,6 @@ export {
25
23
  SpeechRecognizerErrorAndroid,
26
24
  } from "./constants";
27
25
 
28
- export const getSupportedLocales = (options?: {
29
- androidRecognitionServicePackage?: string;
30
- }) => ExpoSpeechRecognitionModule.getSupportedLocales(options ?? {});
31
-
32
- export const getSpeechRecognitionServices =
33
- ExpoSpeechRecognitionModule.getSpeechRecognitionServices;
34
-
35
- export const supportsOnDeviceRecognition =
36
- ExpoSpeechRecognitionModule.supportsOnDeviceRecognition;
37
-
38
- export const supportsRecording = ExpoSpeechRecognitionModule.supportsRecording;
39
-
40
- export const setCategoryIOS = ExpoSpeechRecognitionModule.setCategoryIOS;
41
-
42
- export const getAudioSessionCategoryAndOptionsIOS =
43
- ExpoSpeechRecognitionModule.getAudioSessionCategoryAndOptionsIOS;
44
-
45
- export const setAudioSessionActiveIOS =
46
- ExpoSpeechRecognitionModule.setAudioSessionActiveIOS;
47
-
48
- export const androidTriggerOfflineModelDownload =
49
- ExpoSpeechRecognitionModule.androidTriggerOfflineModelDownload;
50
-
51
- export const isRecognitionAvailable =
52
- ExpoSpeechRecognitionModule.isRecognitionAvailable;
53
-
54
- export const getDefaultRecognitionService =
55
- ExpoSpeechRecognitionModule.getDefaultRecognitionService;
56
-
57
- export const getAssistantService =
58
- ExpoSpeechRecognitionModule.getAssistantService;
59
-
60
- export const addSpeechRecognitionListener =
61
- ExpoSpeechRecognitionModule.addListener;
62
-
63
26
  export type {
64
27
  ExpoSpeechRecognitionOptions,
65
28
  AndroidIntentOptions,