expo-speech-recognition 0.2.24 → 1.0.0
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 +17 -0
- package/README.md +93 -65
- 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.d.ts +0 -2
- package/build/ExpoSpeechRecognitionModule.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.js +6 -18
- package/build/ExpoSpeechRecognitionModule.js.map +1 -1
- package/build/ExpoSpeechRecognitionModule.types.d.ts +34 -3
- package/build/ExpoSpeechRecognitionModule.types.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.types.js.map +1 -1
- package/build/ExpoSpeechRecognitionModule.web.d.ts +43 -10
- package/build/ExpoSpeechRecognitionModule.web.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.web.js +109 -105
- package/build/ExpoSpeechRecognitionModule.web.js.map +1 -1
- package/build/ExpoWebSpeechRecognition.d.ts.map +1 -1
- package/build/ExpoWebSpeechRecognition.js +4 -4
- package/build/ExpoWebSpeechRecognition.js.map +1 -1
- package/build/index.d.ts +3 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -3
- package/build/index.js.map +1 -1
- package/build/useSpeechRecognitionEvent.d.ts +2 -2
- package/build/useSpeechRecognitionEvent.d.ts.map +1 -1
- package/build/useSpeechRecognitionEvent.js +5 -9
- package/build/useSpeechRecognitionEvent.js.map +1 -1
- package/ios/ExpoSpeechRecognitionModule.swift +2 -0
- package/package.json +9 -4
- package/src/ExpoSpeechRecognitionModule.ts +6 -32
- package/src/ExpoSpeechRecognitionModule.types.ts +38 -3
- package/src/ExpoSpeechRecognitionModule.web.ts +172 -145
- package/src/ExpoWebSpeechRecognition.ts +5 -8
- package/src/index.ts +22 -33
- package/src/useSpeechRecognitionEvent.ts +11 -19
|
@@ -1,15 +1,118 @@
|
|
|
1
|
-
import type { PermissionResponse } from "expo-modules-core";
|
|
1
|
+
import type { EventSubscription, PermissionResponse } from "expo-modules-core";
|
|
2
|
+
import { registerWebModule, NativeModule } from "expo";
|
|
2
3
|
import type {
|
|
3
|
-
ExpoSpeechRecognitionModuleType,
|
|
4
4
|
ExpoSpeechRecognitionNativeEventMap,
|
|
5
|
+
ExpoSpeechRecognitionNativeEvents,
|
|
6
|
+
ExpoSpeechRecognitionOptions,
|
|
5
7
|
} from "./ExpoSpeechRecognitionModule.types";
|
|
6
8
|
|
|
7
9
|
let _speechRecognitionRef: SpeechRecognition | null = null;
|
|
8
10
|
|
|
11
|
+
type NativeEventListener = (
|
|
12
|
+
event: SpeechRecognitionEventMap[keyof SpeechRecognitionEventMap],
|
|
13
|
+
) => void;
|
|
14
|
+
|
|
9
15
|
// It loads the native module object from the JSI or falls back to
|
|
10
16
|
// the bridge module (from NativeModulesProxy) if the remote debugger is on.
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
class ExpoSpeechRecognitionModuleWeb extends NativeModule<ExpoSpeechRecognitionNativeEvents> {
|
|
18
|
+
_clientListeners: Map<
|
|
19
|
+
// Original listener
|
|
20
|
+
ExpoSpeechRecognitionNativeEvents[keyof ExpoSpeechRecognitionNativeEvents],
|
|
21
|
+
// Native listener
|
|
22
|
+
NativeEventListener
|
|
23
|
+
> = new Map();
|
|
24
|
+
|
|
25
|
+
_nativeListeners: Map<string, Set<NativeEventListener>> = new Map();
|
|
26
|
+
|
|
27
|
+
// Convert the web event to the native event
|
|
28
|
+
bindEventListener = <T extends keyof SpeechRecognitionEventMap>(
|
|
29
|
+
eventName: T,
|
|
30
|
+
ev: SpeechRecognitionEventMap[T],
|
|
31
|
+
) => {
|
|
32
|
+
const eventPayload = webToNativeEventMap[eventName]?.(ev);
|
|
33
|
+
|
|
34
|
+
this.emit(
|
|
35
|
+
eventName,
|
|
36
|
+
// @ts-expect-error payload typings are incorrect
|
|
37
|
+
eventPayload,
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
addListener<EventName extends keyof ExpoSpeechRecognitionNativeEventMap>(
|
|
42
|
+
eventName: EventName,
|
|
43
|
+
listener: ExpoSpeechRecognitionNativeEvents[EventName],
|
|
44
|
+
): EventSubscription {
|
|
45
|
+
// Convert the web event to the native event
|
|
46
|
+
|
|
47
|
+
// @ts-expect-error Not all events are covered here
|
|
48
|
+
const nativeListener = (ev: SpeechRecognitionEventMap[EventName]) => {
|
|
49
|
+
const handler =
|
|
50
|
+
eventName in webToNativeEventMap
|
|
51
|
+
? webToNativeEventMap[eventName as keyof SpeechRecognitionEventMap]
|
|
52
|
+
: null;
|
|
53
|
+
|
|
54
|
+
// @ts-expect-error payload typings are incorrect
|
|
55
|
+
const eventPayload = handler?.(ev);
|
|
56
|
+
|
|
57
|
+
// @ts-expect-error
|
|
58
|
+
listener(eventPayload);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
_speechRecognitionRef?.addEventListener(eventName, nativeListener);
|
|
63
|
+
if (!this._nativeListeners.has(eventName)) {
|
|
64
|
+
this._nativeListeners.set(eventName, new Set());
|
|
65
|
+
}
|
|
66
|
+
// Add the original listener to the enhanced listeners
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
this._nativeListeners.get(eventName)?.add(nativeListener);
|
|
69
|
+
// Map the original listener to the enhanced listener
|
|
70
|
+
// @ts-expect-error
|
|
71
|
+
this._clientListeners.set(listener, nativeListener);
|
|
72
|
+
|
|
73
|
+
const handle = super.addListener(eventName, listener);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
remove: () => {
|
|
77
|
+
// @ts-expect-error
|
|
78
|
+
this._nativeListeners.get(eventName)?.delete(nativeListener);
|
|
79
|
+
this._clientListeners.delete(listener);
|
|
80
|
+
handle.remove();
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
removeAllListeners(
|
|
86
|
+
eventName: keyof ExpoSpeechRecognitionNativeEventMap,
|
|
87
|
+
): void {
|
|
88
|
+
// Go through _listeners and remove all listeners for this event
|
|
89
|
+
if (this._nativeListeners.has(eventName)) {
|
|
90
|
+
const nativeListeners = this._nativeListeners.get(eventName);
|
|
91
|
+
if (!nativeListeners) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Remove the enhanced listeners
|
|
96
|
+
for (const [listener, nativeListener] of this._clientListeners) {
|
|
97
|
+
// if nativeListener in listeners, remove it
|
|
98
|
+
if (nativeListeners.has(nativeListener)) {
|
|
99
|
+
// Remove the enhanced listener
|
|
100
|
+
this.removeListener(eventName, listener);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ...and the native listeners
|
|
105
|
+
for (const listener of nativeListeners) {
|
|
106
|
+
// @ts-expect-error
|
|
107
|
+
this.removeListener(eventName, listener);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Clean up
|
|
111
|
+
this._nativeListeners.delete(eventName);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
start(options: ExpoSpeechRecognitionOptions) {
|
|
13
116
|
const SpeechRecognitionClass =
|
|
14
117
|
typeof webkitSpeechRecognition !== "undefined"
|
|
15
118
|
? webkitSpeechRecognition
|
|
@@ -22,36 +125,42 @@ export const ExpoSpeechRecognitionModule: ExpoSpeechRecognitionModuleType = {
|
|
|
22
125
|
|
|
23
126
|
// Re-subscribe to events so that we don't lose them
|
|
24
127
|
// This covers the case where the user has already subscribed to an event prior to calling `start()`
|
|
25
|
-
|
|
26
|
-
(listeners
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
);
|
|
128
|
+
this._nativeListeners.forEach((listeners, eventName) => {
|
|
129
|
+
for (const listener of listeners) {
|
|
130
|
+
// May already be subscribed
|
|
131
|
+
_speechRecognitionRef?.removeEventListener(eventName, listener);
|
|
132
|
+
_speechRecognitionRef?.addEventListener(eventName, listener);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
34
135
|
|
|
35
136
|
// Start the speech recognition!
|
|
36
137
|
_speechRecognitionRef.start();
|
|
37
|
-
}
|
|
38
|
-
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getStateAsync() {
|
|
39
141
|
console.warn(
|
|
40
142
|
"getStateAsync is not supported on web. Returning 'inactive'.",
|
|
41
143
|
);
|
|
42
144
|
return Promise.resolve("inactive");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
stop() {
|
|
148
|
+
_speechRecognitionRef?.stop();
|
|
149
|
+
}
|
|
150
|
+
abort() {
|
|
151
|
+
_speechRecognitionRef?.abort();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
requestPermissionsAsync() {
|
|
47
155
|
return Promise.resolve({
|
|
48
156
|
granted: true,
|
|
49
157
|
canAskAgain: false,
|
|
50
158
|
expires: "never",
|
|
51
159
|
status: "granted",
|
|
52
160
|
} as PermissionResponse);
|
|
53
|
-
}
|
|
54
|
-
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getPermissionsAsync() {
|
|
55
164
|
console.warn(
|
|
56
165
|
"getPermissionsAsync is not supported on web. Returning a denied permission response.",
|
|
57
166
|
);
|
|
@@ -61,8 +170,9 @@ export const ExpoSpeechRecognitionModule: ExpoSpeechRecognitionModuleType = {
|
|
|
61
170
|
expires: "never",
|
|
62
171
|
status: "denied",
|
|
63
172
|
} as PermissionResponse);
|
|
64
|
-
}
|
|
65
|
-
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async getSupportedLocales() {
|
|
66
176
|
console.warn(
|
|
67
177
|
"getSupportedLocales is not supported on web. Returning an empty array.",
|
|
68
178
|
);
|
|
@@ -70,37 +180,37 @@ export const ExpoSpeechRecognitionModule: ExpoSpeechRecognitionModuleType = {
|
|
|
70
180
|
locales: [] as string[],
|
|
71
181
|
installedLocales: [] as string[],
|
|
72
182
|
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
console.warn(
|
|
81
|
-
"removeListeners is not supported. Use ExpoSpeechRecognitionModuleEmitter.removeListener(eventName, listener) instead.",
|
|
82
|
-
);
|
|
83
|
-
},
|
|
84
|
-
getSpeechRecognitionServices: () => {
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// addListener() {}
|
|
186
|
+
|
|
187
|
+
// removeListeners() {}
|
|
188
|
+
|
|
189
|
+
getSpeechRecognitionServices() {
|
|
85
190
|
return [] as string[];
|
|
86
|
-
}
|
|
87
|
-
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
getDefaultRecognitionService() {
|
|
88
194
|
return {
|
|
89
195
|
packageName: "",
|
|
90
196
|
};
|
|
91
|
-
}
|
|
92
|
-
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
getAssistantService() {
|
|
93
200
|
return {
|
|
94
201
|
packageName: "",
|
|
95
202
|
};
|
|
96
|
-
}
|
|
97
|
-
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
supportsOnDeviceRecognition() {
|
|
98
206
|
return false;
|
|
99
|
-
}
|
|
100
|
-
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
supportsRecording() {
|
|
101
210
|
return false;
|
|
102
|
-
}
|
|
103
|
-
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
androidTriggerOfflineModelDownload() {
|
|
104
214
|
console.warn(
|
|
105
215
|
"androidTriggerOfflineModelDownload is not supported on web. Returning false.",
|
|
106
216
|
);
|
|
@@ -108,11 +218,13 @@ export const ExpoSpeechRecognitionModule: ExpoSpeechRecognitionModuleType = {
|
|
|
108
218
|
status: "opened_dialog",
|
|
109
219
|
message: "Offline model download is not supported on web.",
|
|
110
220
|
});
|
|
111
|
-
}
|
|
112
|
-
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
setCategoryIOS() {
|
|
113
224
|
console.warn("setCategoryIOS is not supported on web.");
|
|
114
|
-
}
|
|
115
|
-
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
getAudioSessionCategoryAndOptionsIOS() {
|
|
116
228
|
console.warn(
|
|
117
229
|
"getAudioSessionCategoryAndOptionsIOS is not supported on web.",
|
|
118
230
|
);
|
|
@@ -121,18 +233,20 @@ export const ExpoSpeechRecognitionModule: ExpoSpeechRecognitionModuleType = {
|
|
|
121
233
|
categoryOptions: ["defaultToSpeaker", "allowBluetooth"],
|
|
122
234
|
mode: "measurement",
|
|
123
235
|
};
|
|
124
|
-
}
|
|
125
|
-
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
setAudioSessionActiveIOS() {
|
|
126
239
|
console.warn("setAudioSessionActiveIOS is not supported on web.");
|
|
127
|
-
}
|
|
128
|
-
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
isRecognitionAvailable() {
|
|
129
243
|
const hasSpeechRecognitionAPI =
|
|
130
244
|
typeof webkitSpeechRecognition !== "undefined" ||
|
|
131
245
|
typeof SpeechRecognition !== "undefined";
|
|
132
246
|
|
|
133
247
|
return hasSpeechRecognitionAPI;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
136
250
|
|
|
137
251
|
/**
|
|
138
252
|
* Convert the web SpeechRecognitionEventMap to the native event map for compatibility
|
|
@@ -172,93 +286,6 @@ const webToNativeEventMap: {
|
|
|
172
286
|
soundend: (ev) => null,
|
|
173
287
|
};
|
|
174
288
|
|
|
175
|
-
export const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
// Original listener
|
|
179
|
-
(event: any) => void,
|
|
180
|
-
// Native listener
|
|
181
|
-
(event: any) => void
|
|
182
|
-
>,
|
|
183
|
-
addListener<T extends keyof SpeechRecognitionEventMap>(
|
|
184
|
-
eventName: T,
|
|
185
|
-
listener: (ev: ExpoSpeechRecognitionNativeEventMap[T]) => void,
|
|
186
|
-
) {
|
|
187
|
-
// Convert the web event to the native event
|
|
188
|
-
const nativeListener = (ev: SpeechRecognitionEventMap[T]) => {
|
|
189
|
-
const eventPayload = webToNativeEventMap[eventName]?.(ev);
|
|
190
|
-
listener(eventPayload);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
_speechRecognitionRef?.addEventListener(eventName, nativeListener);
|
|
194
|
-
if (!ExpoSpeechRecognitionModuleEmitter._nativeListeners.has(eventName)) {
|
|
195
|
-
ExpoSpeechRecognitionModuleEmitter._nativeListeners.set(
|
|
196
|
-
eventName,
|
|
197
|
-
new Set(),
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
// Add the original listener to the enhanced listeners
|
|
201
|
-
ExpoSpeechRecognitionModuleEmitter._nativeListeners
|
|
202
|
-
.get(eventName)
|
|
203
|
-
?.add(nativeListener);
|
|
204
|
-
|
|
205
|
-
// Map the original listener to the enhanced listener
|
|
206
|
-
ExpoSpeechRecognitionModuleEmitter._clientListeners.set(
|
|
207
|
-
listener,
|
|
208
|
-
nativeListener,
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
return {
|
|
212
|
-
remove: () => {
|
|
213
|
-
_speechRecognitionRef?.removeEventListener(eventName, nativeListener);
|
|
214
|
-
ExpoSpeechRecognitionModuleEmitter._nativeListeners
|
|
215
|
-
.get(eventName)
|
|
216
|
-
?.delete(nativeListener);
|
|
217
|
-
ExpoSpeechRecognitionModuleEmitter._clientListeners.delete(listener);
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
},
|
|
221
|
-
removeListener: (eventName: string, listener: (event: any) => void) => {
|
|
222
|
-
const resolvedListener =
|
|
223
|
-
ExpoSpeechRecognitionModuleEmitter._clientListeners.get(listener) ??
|
|
224
|
-
listener;
|
|
225
|
-
|
|
226
|
-
_speechRecognitionRef?.removeEventListener(eventName, resolvedListener);
|
|
227
|
-
if (ExpoSpeechRecognitionModuleEmitter._nativeListeners.has(eventName)) {
|
|
228
|
-
ExpoSpeechRecognitionModuleEmitter._nativeListeners
|
|
229
|
-
.get(eventName)
|
|
230
|
-
?.delete(listener);
|
|
231
|
-
}
|
|
232
|
-
ExpoSpeechRecognitionModuleEmitter._clientListeners.delete(listener);
|
|
233
|
-
},
|
|
234
|
-
removeAllListeners: (eventName: string) => {
|
|
235
|
-
// Go through _listeners and remove all listeners for this event
|
|
236
|
-
if (ExpoSpeechRecognitionModuleEmitter._nativeListeners.has(eventName)) {
|
|
237
|
-
const nativeListeners =
|
|
238
|
-
ExpoSpeechRecognitionModuleEmitter._nativeListeners.get(eventName);
|
|
239
|
-
if (!nativeListeners) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Remove the enhanced listeners
|
|
244
|
-
for (const [
|
|
245
|
-
listener,
|
|
246
|
-
nativeListener,
|
|
247
|
-
] of ExpoSpeechRecognitionModuleEmitter._clientListeners) {
|
|
248
|
-
// if nativeListener in listeners, remove it
|
|
249
|
-
if (nativeListeners.has(nativeListener)) {
|
|
250
|
-
// Remove the enhanced listener
|
|
251
|
-
ExpoSpeechRecognitionModuleEmitter._clientListeners.delete(listener);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Remove the native listeners
|
|
256
|
-
for (const listener of nativeListeners) {
|
|
257
|
-
ExpoSpeechRecognitionModuleEmitter.removeListener(eventName, listener);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// Clean up
|
|
261
|
-
ExpoSpeechRecognitionModuleEmitter._nativeListeners.delete(eventName);
|
|
262
|
-
}
|
|
263
|
-
},
|
|
264
|
-
};
|
|
289
|
+
export const ExpoSpeechRecognitionModule = registerWebModule(
|
|
290
|
+
ExpoSpeechRecognitionModuleWeb,
|
|
291
|
+
);
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type { Subscription } from "expo-modules-core";
|
|
2
|
-
|
|
3
1
|
// Import the native module. On web, it will be resolved to ExpoSpeechRecognition.web.ts
|
|
4
2
|
// and on native platforms to ExpoSpeechRecognition.ts
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
ExpoSpeechRecognitionModuleEmitter,
|
|
8
|
-
} from "./ExpoSpeechRecognitionModule";
|
|
3
|
+
import type { EventSubscription } from "expo-modules-core";
|
|
4
|
+
import { ExpoSpeechRecognitionModule } from "./ExpoSpeechRecognitionModule";
|
|
9
5
|
import type {
|
|
10
6
|
ExpoSpeechRecognitionNativeEventMap,
|
|
11
7
|
ExpoSpeechRecognitionOptions,
|
|
@@ -210,7 +206,7 @@ export class ExpoWebSpeechRecognition implements SpeechRecognition {
|
|
|
210
206
|
androidRecognitionServicePackage: ExpoSpeechRecognitionOptions["androidRecognitionServicePackage"];
|
|
211
207
|
|
|
212
208
|
// keyed by listener function
|
|
213
|
-
#subscriptionMap: Map<SpeechListener<any>,
|
|
209
|
+
#subscriptionMap: Map<SpeechListener<any>, EventSubscription[]> = new Map();
|
|
214
210
|
|
|
215
211
|
start() {
|
|
216
212
|
ExpoSpeechRecognitionModule.requestPermissionsAsync().then(() => {
|
|
@@ -381,8 +377,9 @@ export class ExpoWebSpeechRecognition implements SpeechRecognition {
|
|
|
381
377
|
wrappedListener as (this: SpeechRecognition, ev: Event) => unknown,
|
|
382
378
|
);
|
|
383
379
|
|
|
384
|
-
const subscription =
|
|
380
|
+
const subscription = ExpoSpeechRecognitionModule.addListener(
|
|
385
381
|
enhancedEvent.eventName,
|
|
382
|
+
// @ts-expect-error
|
|
386
383
|
enhancedEvent.nativeListener,
|
|
387
384
|
);
|
|
388
385
|
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ExpoSpeechRecognitionModule,
|
|
3
|
-
ExpoSpeechRecognitionModuleEmitter,
|
|
4
|
-
} from "./ExpoSpeechRecognitionModule";
|
|
5
|
-
import type { ExpoSpeechRecognitionNativeEventMap } from "./ExpoSpeechRecognitionModule.types";
|
|
1
|
+
import { ExpoSpeechRecognitionModule } from "./ExpoSpeechRecognitionModule";
|
|
6
2
|
|
|
7
3
|
// Export the SpeechRecognition APIs
|
|
8
4
|
export {
|
|
@@ -12,10 +8,7 @@ export {
|
|
|
12
8
|
} from "./ExpoWebSpeechRecognition";
|
|
13
9
|
|
|
14
10
|
// Native module
|
|
15
|
-
export {
|
|
16
|
-
ExpoSpeechRecognitionModule,
|
|
17
|
-
ExpoSpeechRecognitionModuleEmitter,
|
|
18
|
-
} from "./ExpoSpeechRecognitionModule";
|
|
11
|
+
export { ExpoSpeechRecognitionModule } from "./ExpoSpeechRecognitionModule";
|
|
19
12
|
|
|
20
13
|
// Hooks
|
|
21
14
|
export { useSpeechRecognitionEvent } from "./useSpeechRecognitionEvent";
|
|
@@ -63,28 +56,24 @@ export const getDefaultRecognitionService =
|
|
|
63
56
|
export const getAssistantService =
|
|
64
57
|
ExpoSpeechRecognitionModule.getAssistantService;
|
|
65
58
|
|
|
66
|
-
export const addSpeechRecognitionListener =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
type ExpoSpeechRecognitionErrorEvent,
|
|
87
|
-
type ExpoSpeechRecognitionResultEvent,
|
|
88
|
-
type ExpoSpeechRecognitionResult,
|
|
89
|
-
type ExpoSpeechRecognitionResultSegment,
|
|
59
|
+
export const addSpeechRecognitionListener =
|
|
60
|
+
ExpoSpeechRecognitionModule.addListener;
|
|
61
|
+
|
|
62
|
+
export type {
|
|
63
|
+
ExpoSpeechRecognitionOptions,
|
|
64
|
+
AndroidIntentOptions,
|
|
65
|
+
ExpoSpeechRecognitionNativeEventMap,
|
|
66
|
+
AVAudioSessionCategoryOptionsValue,
|
|
67
|
+
AVAudioSessionModeValue,
|
|
68
|
+
AVAudioSessionCategoryValue,
|
|
69
|
+
AudioEncodingAndroidValue,
|
|
70
|
+
AudioSourceOptions,
|
|
71
|
+
RecordingOptions,
|
|
72
|
+
IOSTaskHintValue,
|
|
73
|
+
SetCategoryOptions,
|
|
74
|
+
ExpoSpeechRecognitionErrorCode,
|
|
75
|
+
ExpoSpeechRecognitionErrorEvent,
|
|
76
|
+
ExpoSpeechRecognitionResultEvent,
|
|
77
|
+
ExpoSpeechRecognitionResult,
|
|
78
|
+
ExpoSpeechRecognitionResultSegment,
|
|
90
79
|
} from "./ExpoSpeechRecognitionModule.types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { ExpoSpeechRecognitionModule } from "./ExpoSpeechRecognitionModule";
|
|
2
|
+
import type { ExpoSpeechRecognitionNativeEvents } from "./ExpoSpeechRecognitionModule.types";
|
|
3
|
+
import { useEventListener } from "expo";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* This hook allows you to listen to native events emitted by the `ExpoSpeechRecognitionModule`.
|
|
@@ -11,20 +11,12 @@ import type { ExpoSpeechRecognitionNativeEventMap } from "./ExpoSpeechRecognitio
|
|
|
11
11
|
* @param listener The listener function to call when the event is emitted
|
|
12
12
|
*/
|
|
13
13
|
export function useSpeechRecognitionEvent<
|
|
14
|
-
K extends keyof
|
|
15
|
-
>(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
const handler = listenerRef.current;
|
|
24
|
-
const subscription = ExpoSpeechRecognitionModuleEmitter.addListener(
|
|
25
|
-
eventName,
|
|
26
|
-
handler,
|
|
27
|
-
);
|
|
28
|
-
return subscription.remove;
|
|
29
|
-
}, [eventName]);
|
|
14
|
+
K extends keyof ExpoSpeechRecognitionNativeEvents,
|
|
15
|
+
>(eventName: K, listener: ExpoSpeechRecognitionNativeEvents[K]) {
|
|
16
|
+
return useEventListener(
|
|
17
|
+
ExpoSpeechRecognitionModule,
|
|
18
|
+
eventName,
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
listener,
|
|
21
|
+
);
|
|
30
22
|
}
|