expo-speech-recognition 58.0.2 → 58.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Package.swift +29 -0
- package/build/ExpoWebSpeechRecognition.d.ts.map +1 -1
- package/build/ExpoWebSpeechRecognition.js +18 -16
- package/build/ExpoWebSpeechRecognition.js.map +1 -1
- package/ios/MicrophoneRequester.swift +1 -0
- package/jest.config.js +5 -0
- package/package.json +3 -3
- package/src/ExpoWebSpeechRecognition.ts +32 -16
package/Package.swift
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// swift-tools-version: 6.2
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
// Expo's SwiftPM plugin builds this manifest through a symlink to this directory at
|
|
5
|
+
// `<app>/ios/build/generated/autolinking/expo/direct/expo-speech-recognition`. Relative package
|
|
6
|
+
// paths such as `../ExpoModulesCoreHeaders` resolve against that symlink, not against this directory.
|
|
7
|
+
let package = Package(
|
|
8
|
+
name: "expo-speech-recognition",
|
|
9
|
+
platforms: [
|
|
10
|
+
.iOS("16.4")
|
|
11
|
+
],
|
|
12
|
+
products: [
|
|
13
|
+
.library(name: "ExpoSpeechRecognition", targets: ["ExpoSpeechRecognition"])
|
|
14
|
+
],
|
|
15
|
+
dependencies: [
|
|
16
|
+
.package(path: "../ExpoModulesCoreHeaders")
|
|
17
|
+
],
|
|
18
|
+
targets: [
|
|
19
|
+
.target(
|
|
20
|
+
name: "ExpoSpeechRecognition",
|
|
21
|
+
dependencies: [
|
|
22
|
+
.product(name: "ExpoModulesCoreHeaders", package: "ExpoModulesCoreHeaders")
|
|
23
|
+
],
|
|
24
|
+
path: "ios",
|
|
25
|
+
exclude: ["ExpoSpeechRecognition.podspec"]
|
|
26
|
+
)
|
|
27
|
+
],
|
|
28
|
+
swiftLanguageModes: [.v5]
|
|
29
|
+
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoWebSpeechRecognition.d.ts","sourceRoot":"","sources":["../src/ExpoWebSpeechRecognition.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,4BAA4B,EAC7B,MAAM,qCAAqC,CAAC;AAmJ7C,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,yBAAyB,IAAI,CAC/D,IAAI,EAAE,iBAAiB,EACvB,EAAE,EAAE,yBAAyB,CAAC,CAAC,CAAC,KAC7B,GAAG,CAAC;AAET,8FAA8F;AAC9F,qBAAa,wBAAyB,YAAW,iBAAiB;;IAChE,IAAI,SAAW;IACf,QAAQ,EAAE,iBAAiB,CAAkC;IAC7D,eAAe,SAAK;IACpB,UAAU,UAAS;IACnB,cAAc,UAAS;IAIvB,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED,IAAI,cAAc,CAAC,cAAc,EAAE,OAAO,EAGzC;IAID,gIAAgI;IAChI,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAa;IACzC,uIAAuI;IACvI,2BAA2B,UAAS;IACpC,oHAAoH;IACpH,eAAe,UAAS;IACxB,yFAAyF;IACzF,oBAAoB,EAAE,4BAA4B,CAAC,sBAAsB,CAAC,CAAC;IAC3E,qFAAqF;IACrF,WAAW,CAAC,EAAE,4BAA4B,CAAC,aAAa,CAAC,CAAC;IAC1D,wFAAwF;IACxF,gBAAgB,CAAC,EAAE,4BAA4B,CAAC,kBAAkB,CAAC,CAAC;IACpE,8FAA8F;IAC9F,aAAa,CAAC,EAAE,4BAA4B,CAAC,eAAe,CAAC,CAAa;IAC1E,+EAA+E;IAC/E,WAAW,CAAC,EAAE,4BAA4B,CAAC,aAAa,CAAC,CAAa;IACtE,oFAAoF;IACpF,WAAW,CAAC,EAAE,4BAA4B,CAAC,aAAa,CAAC,CAAa;IACtE;;;;;;;;;OASG;IACH,gCAAgC,EAAE,4BAA4B,CAAC,kCAAkC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpoWebSpeechRecognition.d.ts","sourceRoot":"","sources":["../src/ExpoW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AAM,GAAG,SAAS,GAAG,IAAI;IAI1D,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB;IAIzC,aAAa,GAAI,SAAS,MAAM,EAAE,SAAS,MAAM,UAK/C;CACH;AAED,qBAAa,oBAAqB,YAAW,aAAa;IACxD,GAAG,SAAM;IACT,MAAM,SAAK;gBAEC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAIzC"}
|
|
@@ -152,8 +152,7 @@ export class ExpoWebSpeechRecognition {
|
|
|
152
152
|
* e.g. com.samsung.android.bixby.agent"
|
|
153
153
|
*/
|
|
154
154
|
androidRecognitionServicePackage;
|
|
155
|
-
|
|
156
|
-
#subscriptionMap = new Map();
|
|
155
|
+
#subscriptions = [];
|
|
157
156
|
start() {
|
|
158
157
|
ExpoSpeechRecognitionModule.requestPermissionsAsync().then(() => {
|
|
159
158
|
// A result doesn't matter,
|
|
@@ -275,17 +274,21 @@ export class ExpoWebSpeechRecognition {
|
|
|
275
274
|
/** [TODO] */
|
|
276
275
|
onsoundstart = null;
|
|
277
276
|
addEventListener(type, listener, options) {
|
|
277
|
+
const capture = typeof options === "boolean" ? options : !!options?.capture;
|
|
278
|
+
if (this.#subscriptions.some((entry) => entry.type === type &&
|
|
279
|
+
entry.listener === listener &&
|
|
280
|
+
entry.capture === capture)) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
278
283
|
const once = typeof options === "object" && options.once;
|
|
279
284
|
// If the user opts in to only listening once,
|
|
280
285
|
// wrap the listener in a function that removes the listener
|
|
281
286
|
const wrappedListener = once
|
|
282
287
|
? ((ev) => {
|
|
288
|
+
// Remove before invoking the callback so nested delivery and
|
|
289
|
+
// registrations made inside the callback keep their own lifetime.
|
|
290
|
+
this.removeEventListener(type, listener, capture);
|
|
283
291
|
listener.call(this, ev);
|
|
284
|
-
// remove the listeners from the map
|
|
285
|
-
for (const sub of this.#subscriptionMap.get(listener) ?? []) {
|
|
286
|
-
sub.remove();
|
|
287
|
-
}
|
|
288
|
-
this.#subscriptionMap.delete(listener);
|
|
289
292
|
})
|
|
290
293
|
: listener;
|
|
291
294
|
// Enhance the native listener with any necessary polyfills
|
|
@@ -294,17 +297,16 @@ export class ExpoWebSpeechRecognition {
|
|
|
294
297
|
const subscription = ExpoSpeechRecognitionModule.addListener(enhancedEvent.eventName,
|
|
295
298
|
// @ts-expect-error
|
|
296
299
|
enhancedEvent.nativeListener);
|
|
297
|
-
|
|
298
|
-
// This is keyed by the listener function so we can remove all subscriptions for a given listener
|
|
299
|
-
this.#subscriptionMap.set(listener, [subscription]);
|
|
300
|
+
this.#subscriptions.push({ type, listener, capture, subscription });
|
|
300
301
|
}
|
|
301
302
|
removeEventListener(type, listener, options) {
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.#
|
|
303
|
+
const capture = typeof options === "boolean" ? options : !!options?.capture;
|
|
304
|
+
const index = this.#subscriptions.findIndex((entry) => entry.type === type &&
|
|
305
|
+
entry.listener === listener &&
|
|
306
|
+
entry.capture === capture);
|
|
307
|
+
if (index !== -1) {
|
|
308
|
+
const [registration] = this.#subscriptions.splice(index, 1);
|
|
309
|
+
registration?.subscription.remove();
|
|
308
310
|
}
|
|
309
311
|
}
|
|
310
312
|
dispatchEvent(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoWebSpeechRecognition.js","sourceRoot":"","sources":["../src/ExpoWebSpeechRecognition.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAM5E,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEtB,MAAM,eAAe,GAAG,CAAC,MAAmB,EAAE,EAAE,CAAC,CAAC;IAChD,SAAS,EAAE,CAAU;IACrB,OAAO,EAAE,KAAK;IACd,cAAc,EAAE,CAAU;IAC1B,UAAU,EAAE,KAAK;IACjB,eAAe,EAAE,CAAU;I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G,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAE,CAAC;QAC7B,CAAC;IACH,CAAC;CACF;AAED,MAAM,gCAAgC;IACpC,UAAU,CAAS;IACnB,UAAU,CAAS;IAEnB,YAAY,UAAkB,EAAE,UAAkB;QAChD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF","sourcesContent":["// Import the native module. On web, it will be resolved to ExpoSpeechRecognition.web.ts\n// and on native platforms to ExpoSpeechRecognition.ts\nimport type { EventSubscription } from \"expo-modules-core\";\nimport { ExpoSpeechRecognitionModule } from \"./ExpoSpeechRecognitionModule\";\nimport type {\n ExpoSpeechRecognitionNativeEventMap,\n ExpoSpeechRecognitionOptions,\n} from \"./ExpoSpeechRecognitionModule.types\";\n\nconst noop = () => {};\n\nconst createEventData = (target: EventTarget) => ({\n AT_TARGET: 2 as const,\n bubbles: false,\n BUBBLING_PHASE: 3 as const,\n cancelable: false,\n CAPTURING_PHASE: 1 as const,\n composed: false,\n composedPath: () => [],\n currentTarget: target,\n defaultPrevented: false,\n eventPhase: 0,\n isTrusted: true,\n NONE: 0 as const,\n preventDefault: noop,\n resultIndex: 0,\n stopImmediatePropagation: noop,\n stopPropagation: noop,\n target,\n timeStamp: 0,\n type: \"\",\n cancelBubble: false,\n returnValue: false,\n srcElement: null,\n initEvent: noop,\n});\n\ntype NativeEventAndListener<\n TEventName extends keyof ExpoSpeechRecognitionNativeEventMap,\n> = {\n /** Event name to listen for on native side */\n eventName: TEventName;\n nativeListener: (\n nativeEvent: ExpoSpeechRecognitionNativeEventMap[TEventName],\n ) => void;\n};\n\nfunction stubEvent<K extends keyof SpeechRecognitionEventMap>(\n eventName: K,\n instance: ExpoWebSpeechRecognition,\n listener: (this: SpeechRecognition, ev: Event) => unknown,\n): NativeEventAndListener<K> {\n return {\n eventName,\n nativeListener: (nativeEvent) =>\n listener.call(instance, createEventData(instance)),\n };\n}\n\n/**\n * Transforms the native listener payloads to web-compatible shapes\n */\nconst WebListenerTransformers: {\n [K in keyof SpeechRecognitionEventMap]?: (\n instance: ExpoWebSpeechRecognition,\n listener: (\n this: SpeechRecognition,\n ev: SpeechRecognitionEventMap[K],\n ) => unknown,\n ) => NativeEventAndListener<K>;\n} = {\n audiostart: (instance, listener) => {\n return {\n eventName: \"audiostart\",\n nativeListener(nativeEvent) {\n listener.call(instance, {\n ...createEventData(instance),\n uri: nativeEvent.uri,\n timestamp: nativeEvent.timestamp,\n });\n },\n };\n },\n audioend: (instance, listener) => {\n return {\n eventName: \"audioend\",\n nativeListener(nativeEvent) {\n listener.call(instance, {\n ...createEventData(instance),\n uri: nativeEvent.uri,\n timestamp: nativeEvent.timestamp,\n });\n },\n };\n },\n nomatch: (instance, listener) => {\n // @ts-ignore\n return stubEvent(\"nomatch\", instance, listener);\n },\n end: (instance, listener) => {\n return stubEvent(\"end\", instance, listener);\n },\n start: (instance, listener) => {\n return {\n eventName: \"start\",\n nativeListener() {\n listener.call(instance, createEventData(instance));\n },\n };\n },\n error: (instance, listener) => {\n return {\n eventName: \"error\",\n nativeListener: (\n nativeEvent: ExpoSpeechRecognitionNativeEventMap[\"error\"],\n ) => {\n const clientEvent: SpeechRecognitionEventMap[\"error\"] = {\n ...createEventData(instance),\n // TODO: handle custom ios error codes\n error: nativeEvent.error as SpeechRecognitionErrorCode,\n message: nativeEvent.message,\n };\n listener.call(instance, clientEvent);\n },\n };\n },\n result: (instance, listener) => {\n return {\n eventName: \"result\",\n nativeListener: (\n nativeEvent: ExpoSpeechRecognitionNativeEventMap[\"result\"],\n ) => {\n if (!instance.interimResults && !nativeEvent.isFinal) {\n return;\n }\n const alternatives = nativeEvent.results.map(\n (result) =>\n new ExpoSpeechRecognitionAlternative(\n result.confidence,\n result.transcript,\n ),\n );\n const clientEvent: SpeechRecognitionEventMap[\"result\"] = {\n ...createEventData(instance),\n results: new ExpoSpeechRecognitionResultList([\n new ExpoSpeechRecognitionResult(nativeEvent.isFinal, alternatives),\n ]),\n };\n listener.call(instance, clientEvent);\n },\n };\n },\n};\n\ntype SpeechListener<K extends keyof SpeechRecognitionEventMap> = (\n this: SpeechRecognition,\n ev: SpeechRecognitionEventMap[K],\n) => any;\n\n/** A compatibility wrapper that implements the web SpeechRecognition API for React Native. */\nexport class ExpoWebSpeechRecognition implements SpeechRecognition {\n lang = \"en-US\";\n grammars: SpeechGrammarList = new ExpoWebSpeechGrammarList();\n maxAlternatives = 1;\n continuous = false;\n processLocally = false;\n\n #interimResults = false;\n\n get interimResults(): boolean {\n return this.#interimResults;\n }\n\n set interimResults(interimResults: boolean) {\n this.#interimResults = interimResults;\n // Subscribe to native\n }\n\n // Extended properties\n\n /** [EXTENDED, default: undefined] An array of strings that will be used to provide context to the speech recognition engine. */\n contextualStrings?: string[] = undefined;\n /** [EXTENDED, default: false] Whether the speech recognition engine should require the device to be on when the recognition starts. */\n requiresOnDeviceRecognition = false;\n /** [EXTENDED, default: false] Whether the speech recognition engine should add punctuation to the transcription. */\n addsPunctuation = false;\n /** [EXTENDED, default: undefined] Android-specific options to pass to the recognizer. */\n androidIntentOptions: ExpoSpeechRecognitionOptions[\"androidIntentOptions\"];\n /** [EXTENDED, default: undefined] Audio source options to pass to the recognizer. */\n audioSource?: ExpoSpeechRecognitionOptions[\"audioSource\"];\n /** [EXTENDED, default: undefined] Audio recording options to pass to the recognizer. */\n recordingOptions?: ExpoSpeechRecognitionOptions[\"recordingOptions\"];\n /** [EXTENDED, default: \"android.speech.action.RECOGNIZE_SPEECH\"] The kind of intent action */\n androidIntent?: ExpoSpeechRecognitionOptions[\"androidIntent\"] = undefined;\n /** [EXTENDED, default: undefined] The hint for the speech recognition task. */\n iosTaskHint?: ExpoSpeechRecognitionOptions[\"iosTaskHint\"] = undefined;\n /** [EXTENDED, default: undefined] The audio session category and options to use. */\n iosCategory?: ExpoSpeechRecognitionOptions[\"iosCategory\"] = undefined;\n /**\n * [EXTENDED, default: undefined]\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.samsung.android.bixby.agent\"\n */\n androidRecognitionServicePackage: ExpoSpeechRecognitionOptions[\"androidRecognitionServicePackage\"];\n\n // keyed by listener function\n #subscriptionMap: Map<SpeechListener<any>, EventSubscription[]> = new Map();\n\n start() {\n ExpoSpeechRecognitionModule.requestPermissionsAsync().then(() => {\n // A result doesn't matter,\n // the module will emit an error if permissions are not granted\n ExpoSpeechRecognitionModule.start({\n lang: this.lang,\n interimResults: this.interimResults,\n maxAlternatives: this.maxAlternatives,\n contextualStrings: this.contextualStrings,\n requiresOnDeviceRecognition: this.requiresOnDeviceRecognition,\n addsPunctuation: this.addsPunctuation,\n continuous: this.continuous,\n recordingOptions: this.recordingOptions,\n androidIntentOptions: this.androidIntentOptions,\n androidRecognitionServicePackage: this.androidRecognitionServicePackage,\n audioSource: this.audioSource,\n androidIntent: this.androidIntent,\n iosTaskHint: this.iosTaskHint,\n iosCategory: this.iosCategory,\n });\n });\n }\n stop = ExpoSpeechRecognitionModule.stop;\n abort = ExpoSpeechRecognitionModule.abort;\n\n #onstart: SpeechListener<\"start\"> | null = null;\n set onstart(listener: SpeechListener<\"start\"> | null) {\n this._setListeners(\"start\", listener, this.#onstart);\n this.#onstart = listener;\n }\n /** Fired when the speech recognition starts. */\n get onstart() {\n return this.#onstart;\n }\n\n #onend: SpeechListener<\"end\"> | null = null;\n set onend(listener: SpeechListener<\"end\"> | null) {\n this._setListeners(\n \"end\",\n (ev) => {\n listener?.call(this, ev);\n },\n this.#onend,\n );\n this.#onend = listener;\n }\n /** Fired when the speech recognition service has disconnected. */\n get onend() {\n return this.#onend;\n }\n\n #onerror: SpeechListener<\"error\"> | null = null;\n set onerror(listener: SpeechListener<\"error\"> | null) {\n this._setListeners(\"error\", listener, this.#onerror);\n this.#onerror = listener;\n }\n /** Fired when the speech recognition service encounters an error. */\n get onerror() {\n return this.#onerror;\n }\n\n _setListeners<K extends keyof SpeechRecognitionEventMap>(\n key: K,\n listenerFn: SpeechListener<K> | null,\n existingListener: SpeechListener<K> | null,\n ) {\n if (existingListener) {\n this.removeEventListener(key, existingListener);\n }\n if (listenerFn) {\n this.addEventListener(key, listenerFn);\n }\n }\n\n #onresult: SpeechListener<\"result\"> | null = null;\n set onresult(listener: SpeechListener<\"result\"> | null) {\n this._setListeners(\"result\", listener, this.#onresult);\n this.#onresult = listener;\n }\n /** Fired when the speech recognition service returns a result —\n * a word or phrase has been positively recognized and this has been communicated back to the app. */\n get onresult() {\n return this.#onresult;\n }\n\n #onnomatch: SpeechListener<\"nomatch\"> | null = null;\n set onnomatch(listener: SpeechListener<\"nomatch\"> | null) {\n this._setListeners(\"nomatch\", listener, this.#onnomatch);\n this.#onnomatch = listener;\n }\n /** Fired when the speech recognition service returns a final result with no significant recognition. */\n get onnomatch() {\n return this.#onnomatch;\n }\n\n #onspeechstart: SpeechListener<\"speechstart\"> | null = null;\n set onspeechstart(listener: SpeechListener<\"speechstart\"> | null) {\n this._setListeners(\"speechstart\", listener, this.#onspeechstart);\n this.#onspeechstart = listener;\n }\n /** Fired when the speech recognition service returns a final result with no significant recognition. */\n get onspeechstart() {\n return this.#onspeechstart;\n }\n\n #onspeechend: SpeechListener<\"speechend\"> | null = null;\n set onspeechend(listener: SpeechListener<\"speechend\"> | null) {\n this._setListeners(\"speechend\", listener, this.#onspeechend);\n this.#onspeechend = listener;\n }\n /** Fired when the speech recognition service returns a final result with no significant recognition. */\n get onspeechend() {\n return this.#onspeechend;\n }\n\n #onaudiostart: SpeechListener<\"audiostart\"> | null = null;\n set onaudiostart(listener: SpeechListener<\"audiostart\"> | null) {\n this._setListeners(\"audiostart\", listener, this.#onaudiostart);\n this.#onaudiostart = listener;\n }\n /** Fired when the user agent has started to capture audio. */\n get onaudiostart() {\n return this.#onaudiostart;\n }\n\n #onaudioend: SpeechListener<\"audioend\"> | null = null;\n set onaudioend(listener: SpeechListener<\"audioend\"> | null) {\n this._setListeners(\"audioend\", listener, this.#onaudioend);\n this.#onaudioend = listener;\n }\n /** Fired when the user agent has finished capturing audio. */\n get onaudioend() {\n return this.#onaudioend;\n }\n\n /** [TODO] */\n onsoundend: ((this: SpeechRecognition, ev: Event) => any) | null = null;\n /** [TODO] */\n onsoundstart: ((this: SpeechRecognition, ev: Event) => any) | null = null;\n\n addEventListener<K extends keyof SpeechRecognitionEventMap>(\n type: K,\n listener: SpeechListener<K>,\n options?: boolean | AddEventListenerOptions,\n ): void {\n const once = typeof options === \"object\" && options.once;\n\n // If the user opts in to only listening once,\n // wrap the listener in a function that removes the listener\n const wrappedListener = once\n ? (((ev) => {\n listener.call(this, ev);\n // remove the listeners from the map\n for (const sub of this.#subscriptionMap.get(listener) ?? []) {\n sub.remove();\n }\n this.#subscriptionMap.delete(listener);\n }) as SpeechListener<K>)\n : listener;\n\n // Enhance the native listener with any necessary polyfills\n const enhancedEvent: NativeEventAndListener<K> =\n WebListenerTransformers[type]?.(this, wrappedListener) ??\n stubEvent(\n type,\n this,\n wrappedListener as (this: SpeechRecognition, ev: Event) => unknown,\n );\n\n const subscription = ExpoSpeechRecognitionModule.addListener(\n enhancedEvent.eventName,\n // @ts-expect-error\n enhancedEvent.nativeListener,\n );\n\n // Store the subscriptions so we can remove them later\n // This is keyed by the listener function so we can remove all subscriptions for a given listener\n this.#subscriptionMap.set(listener, [subscription]);\n }\n\n removeEventListener<K extends keyof SpeechRecognitionEventMap>(\n type: K,\n listener: (\n this: SpeechRecognition,\n ev: SpeechRecognitionEventMap[K],\n ) => any,\n options?: boolean | EventListenerOptions | undefined,\n ): void {\n const subscriptions = this.#subscriptionMap.get(listener);\n if (subscriptions) {\n for (const subscription of subscriptions) {\n subscription.remove();\n }\n this.#subscriptionMap.delete(listener);\n }\n }\n\n dispatchEvent(event: Event): boolean {\n throw new Error(\"Method not implemented.\");\n }\n}\n\n/**\n * This class is just a polyfill and does nothing on Android/iOS\n */\nexport class ExpoWebSpeechGrammarList implements SpeechGrammarList {\n get length() {\n return this.#grammars.length;\n }\n #grammars: ExpoWebSpeechGrammar[] = [];\n [index: number]: SpeechGrammar; // Indexer property\n\n addFromURI(src: string, weight?: number | undefined): void {\n // todo\n }\n\n item(index: number): ExpoWebSpeechGrammar {\n return this.#grammars[index]!;\n }\n\n addFromString = (grammar: string, weight?: number) => {\n // TODO: parse grammar to html entities (data:application/xml,....)\n this.#grammars.push(new ExpoWebSpeechGrammar(grammar, weight));\n // Set key on this object for compatibility with web SpeechGrammarList API\n this[this.length - 1] = this.#grammars[this.length - 1]!;\n };\n}\n\nexport class ExpoWebSpeechGrammar implements SpeechGrammar {\n src = \"\";\n weight = 1;\n\n constructor(src: string, weight?: number) {\n this.src = src;\n this.weight = weight ?? 1;\n }\n}\n\nclass ExpoSpeechRecognitionResultList implements SpeechRecognitionResultList {\n #results: ExpoSpeechRecognitionResult[] = [];\n\n [Symbol.iterator](): ArrayIterator<ExpoSpeechRecognitionResult> {\n return this.#results[\n Symbol.iterator\n ]() as ArrayIterator<ExpoSpeechRecognitionResult>;\n }\n length: number;\n item(index: number): SpeechRecognitionResult {\n return this.#results[index]!;\n }\n [index: number]: SpeechRecognitionResult;\n\n constructor(results: ExpoSpeechRecognitionResult[]) {\n this.#results = results;\n this.length = results.length;\n for (let i = 0; i < this.#results.length; i++) {\n this[i] = this.#results[i]!;\n }\n }\n}\n\nclass ExpoSpeechRecognitionResult implements SpeechRecognitionResult {\n #alternatives: ExpoSpeechRecognitionAlternative[] = [];\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SpeechRecognitionResult/isFinal) */\n readonly isFinal: boolean;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SpeechRecognitionResult/length) */\n length: number;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SpeechRecognitionResult/item) */\n item(index: number): SpeechRecognitionAlternative {\n return this.#alternatives[index]!;\n }\n [index: number]: SpeechRecognitionAlternative;\n [Symbol.iterator](): ArrayIterator<SpeechRecognitionAlternative> {\n return this.#alternatives[\n Symbol.iterator\n ]() as ArrayIterator<SpeechRecognitionAlternative>;\n }\n\n constructor(\n isFinal: boolean,\n alternatives: ExpoSpeechRecognitionAlternative[],\n ) {\n this.isFinal = isFinal;\n this.length = alternatives.length;\n this.#alternatives = alternatives;\n for (let i = 0; i < alternatives.length; i++) {\n this[i] = alternatives[i]!;\n }\n }\n}\n\nclass ExpoSpeechRecognitionAlternative implements SpeechRecognitionAlternative {\n confidence: number;\n transcript: string;\n\n constructor(confidence: number, transcript: string) {\n this.confidence = confidence;\n this.transcript = transcript;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoWebSpeechRecognition.js","sourceRoot":"","sources":["../src/ExpoWebSpeechRecognition.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAM5E,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEtB,MAAM,eAAe,GAAG,CAAC,MAAmB,EAAE,EAAE,CAAC,CAAC;IAChD,SAAS,EAAE,CAAU;IACrB,OAAO,EAAE,KAAK;IACd,cAAc,EAAE,CAAU;IAC1B,UAAU,EAAE,KAAK;IACjB,eAAe,EAAE,CAAU;IAC3B,QAAQ,EAAE,KAAK;IACf,YAAY,EAAE,GAAG,EAAE,CAAC,EAAE;IACtB,aAAa,EAAE,MAAM;IACrB,gBAAgB,EAAE,KAAK;IACvB,UAAU,EAAE,CAAC;IACb,SAAS,EAAE,IAAI;IACf,IAAI,EAAE,CAAU;IAChB,cAAc,EAAE,IAA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AAI,CAAC,aAAa,CAAC,KAAK,CAAE,CAAC;IACpC,CAAC;IAED,CAAC,MAAM,CAAC,QAAQ,CAAC;QACf,OAAO,IAAI,CAAC,aAAa,CACvB,MAAM,CAAC,QAAQ,CAChB,EAAiD,CAAC;IACrD,CAAC;IAED,YACE,OAAgB,EAChB,YAAgD;QAEhD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,IAAI,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAE,CAAC;QAC7B,CAAC;IACH,CAAC;CACF;AAED,MAAM,gCAAgC;IACpC,UAAU,CAAS;IACnB,UAAU,CAAS;IAEnB,YAAY,UAAkB,EAAE,UAAkB;QAChD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF","sourcesContent":["// Import the native module. On web, it will be resolved to ExpoSpeechRecognition.web.ts\n// and on native platforms to ExpoSpeechRecognition.ts\nimport type { EventSubscription } from \"expo-modules-core\";\nimport { ExpoSpeechRecognitionModule } from \"./ExpoSpeechRecognitionModule\";\nimport type {\n ExpoSpeechRecognitionNativeEventMap,\n ExpoSpeechRecognitionOptions,\n} from \"./ExpoSpeechRecognitionModule.types\";\n\nconst noop = () => {};\n\nconst createEventData = (target: EventTarget) => ({\n AT_TARGET: 2 as const,\n bubbles: false,\n BUBBLING_PHASE: 3 as const,\n cancelable: false,\n CAPTURING_PHASE: 1 as const,\n composed: false,\n composedPath: () => [],\n currentTarget: target,\n defaultPrevented: false,\n eventPhase: 0,\n isTrusted: true,\n NONE: 0 as const,\n preventDefault: noop,\n resultIndex: 0,\n stopImmediatePropagation: noop,\n stopPropagation: noop,\n target,\n timeStamp: 0,\n type: \"\",\n cancelBubble: false,\n returnValue: false,\n srcElement: null,\n initEvent: noop,\n});\n\ntype NativeEventAndListener<\n TEventName extends keyof ExpoSpeechRecognitionNativeEventMap,\n> = {\n /** Event name to listen for on native side */\n eventName: TEventName;\n nativeListener: (\n nativeEvent: ExpoSpeechRecognitionNativeEventMap[TEventName],\n ) => void;\n};\n\nfunction stubEvent<K extends keyof SpeechRecognitionEventMap>(\n eventName: K,\n instance: ExpoWebSpeechRecognition,\n listener: (this: SpeechRecognition, ev: Event) => unknown,\n): NativeEventAndListener<K> {\n return {\n eventName,\n nativeListener: (nativeEvent) =>\n listener.call(instance, createEventData(instance)),\n };\n}\n\n/**\n * Transforms the native listener payloads to web-compatible shapes\n */\nconst WebListenerTransformers: {\n [K in keyof SpeechRecognitionEventMap]?: (\n instance: ExpoWebSpeechRecognition,\n listener: (\n this: SpeechRecognition,\n ev: SpeechRecognitionEventMap[K],\n ) => unknown,\n ) => NativeEventAndListener<K>;\n} = {\n audiostart: (instance, listener) => {\n return {\n eventName: \"audiostart\",\n nativeListener(nativeEvent) {\n listener.call(instance, {\n ...createEventData(instance),\n uri: nativeEvent.uri,\n timestamp: nativeEvent.timestamp,\n });\n },\n };\n },\n audioend: (instance, listener) => {\n return {\n eventName: \"audioend\",\n nativeListener(nativeEvent) {\n listener.call(instance, {\n ...createEventData(instance),\n uri: nativeEvent.uri,\n timestamp: nativeEvent.timestamp,\n });\n },\n };\n },\n nomatch: (instance, listener) => {\n // @ts-ignore\n return stubEvent(\"nomatch\", instance, listener);\n },\n end: (instance, listener) => {\n return stubEvent(\"end\", instance, listener);\n },\n start: (instance, listener) => {\n return {\n eventName: \"start\",\n nativeListener() {\n listener.call(instance, createEventData(instance));\n },\n };\n },\n error: (instance, listener) => {\n return {\n eventName: \"error\",\n nativeListener: (\n nativeEvent: ExpoSpeechRecognitionNativeEventMap[\"error\"],\n ) => {\n const clientEvent: SpeechRecognitionEventMap[\"error\"] = {\n ...createEventData(instance),\n // TODO: handle custom ios error codes\n error: nativeEvent.error as SpeechRecognitionErrorCode,\n message: nativeEvent.message,\n };\n listener.call(instance, clientEvent);\n },\n };\n },\n result: (instance, listener) => {\n return {\n eventName: \"result\",\n nativeListener: (\n nativeEvent: ExpoSpeechRecognitionNativeEventMap[\"result\"],\n ) => {\n if (!instance.interimResults && !nativeEvent.isFinal) {\n return;\n }\n const alternatives = nativeEvent.results.map(\n (result) =>\n new ExpoSpeechRecognitionAlternative(\n result.confidence,\n result.transcript,\n ),\n );\n const clientEvent: SpeechRecognitionEventMap[\"result\"] = {\n ...createEventData(instance),\n results: new ExpoSpeechRecognitionResultList([\n new ExpoSpeechRecognitionResult(nativeEvent.isFinal, alternatives),\n ]),\n };\n listener.call(instance, clientEvent);\n },\n };\n },\n};\n\ntype SpeechListener<K extends keyof SpeechRecognitionEventMap> = (\n this: SpeechRecognition,\n ev: SpeechRecognitionEventMap[K],\n) => any;\n\n/** A compatibility wrapper that implements the web SpeechRecognition API for React Native. */\nexport class ExpoWebSpeechRecognition implements SpeechRecognition {\n lang = \"en-US\";\n grammars: SpeechGrammarList = new ExpoWebSpeechGrammarList();\n maxAlternatives = 1;\n continuous = false;\n processLocally = false;\n\n #interimResults = false;\n\n get interimResults(): boolean {\n return this.#interimResults;\n }\n\n set interimResults(interimResults: boolean) {\n this.#interimResults = interimResults;\n // Subscribe to native\n }\n\n // Extended properties\n\n /** [EXTENDED, default: undefined] An array of strings that will be used to provide context to the speech recognition engine. */\n contextualStrings?: string[] = undefined;\n /** [EXTENDED, default: false] Whether the speech recognition engine should require the device to be on when the recognition starts. */\n requiresOnDeviceRecognition = false;\n /** [EXTENDED, default: false] Whether the speech recognition engine should add punctuation to the transcription. */\n addsPunctuation = false;\n /** [EXTENDED, default: undefined] Android-specific options to pass to the recognizer. */\n androidIntentOptions: ExpoSpeechRecognitionOptions[\"androidIntentOptions\"];\n /** [EXTENDED, default: undefined] Audio source options to pass to the recognizer. */\n audioSource?: ExpoSpeechRecognitionOptions[\"audioSource\"];\n /** [EXTENDED, default: undefined] Audio recording options to pass to the recognizer. */\n recordingOptions?: ExpoSpeechRecognitionOptions[\"recordingOptions\"];\n /** [EXTENDED, default: \"android.speech.action.RECOGNIZE_SPEECH\"] The kind of intent action */\n androidIntent?: ExpoSpeechRecognitionOptions[\"androidIntent\"] = undefined;\n /** [EXTENDED, default: undefined] The hint for the speech recognition task. */\n iosTaskHint?: ExpoSpeechRecognitionOptions[\"iosTaskHint\"] = undefined;\n /** [EXTENDED, default: undefined] The audio session category and options to use. */\n iosCategory?: ExpoSpeechRecognitionOptions[\"iosCategory\"] = undefined;\n /**\n * [EXTENDED, default: undefined]\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.samsung.android.bixby.agent\"\n */\n androidRecognitionServicePackage: ExpoSpeechRecognitionOptions[\"androidRecognitionServicePackage\"];\n\n #subscriptions: {\n type: keyof SpeechRecognitionEventMap;\n listener: SpeechListener<any>;\n capture: boolean;\n subscription: EventSubscription;\n }[] = [];\n\n start() {\n ExpoSpeechRecognitionModule.requestPermissionsAsync().then(() => {\n // A result doesn't matter,\n // the module will emit an error if permissions are not granted\n ExpoSpeechRecognitionModule.start({\n lang: this.lang,\n interimResults: this.interimResults,\n maxAlternatives: this.maxAlternatives,\n contextualStrings: this.contextualStrings,\n requiresOnDeviceRecognition: this.requiresOnDeviceRecognition,\n addsPunctuation: this.addsPunctuation,\n continuous: this.continuous,\n recordingOptions: this.recordingOptions,\n androidIntentOptions: this.androidIntentOptions,\n androidRecognitionServicePackage: this.androidRecognitionServicePackage,\n audioSource: this.audioSource,\n androidIntent: this.androidIntent,\n iosTaskHint: this.iosTaskHint,\n iosCategory: this.iosCategory,\n });\n });\n }\n stop = ExpoSpeechRecognitionModule.stop;\n abort = ExpoSpeechRecognitionModule.abort;\n\n #onstart: SpeechListener<\"start\"> | null = null;\n set onstart(listener: SpeechListener<\"start\"> | null) {\n this._setListeners(\"start\", listener, this.#onstart);\n this.#onstart = listener;\n }\n /** Fired when the speech recognition starts. */\n get onstart() {\n return this.#onstart;\n }\n\n #onend: SpeechListener<\"end\"> | null = null;\n set onend(listener: SpeechListener<\"end\"> | null) {\n this._setListeners(\n \"end\",\n (ev) => {\n listener?.call(this, ev);\n },\n this.#onend,\n );\n this.#onend = listener;\n }\n /** Fired when the speech recognition service has disconnected. */\n get onend() {\n return this.#onend;\n }\n\n #onerror: SpeechListener<\"error\"> | null = null;\n set onerror(listener: SpeechListener<\"error\"> | null) {\n this._setListeners(\"error\", listener, this.#onerror);\n this.#onerror = listener;\n }\n /** Fired when the speech recognition service encounters an error. */\n get onerror() {\n return this.#onerror;\n }\n\n _setListeners<K extends keyof SpeechRecognitionEventMap>(\n key: K,\n listenerFn: SpeechListener<K> | null,\n existingListener: SpeechListener<K> | null,\n ) {\n if (existingListener) {\n this.removeEventListener(key, existingListener);\n }\n if (listenerFn) {\n this.addEventListener(key, listenerFn);\n }\n }\n\n #onresult: SpeechListener<\"result\"> | null = null;\n set onresult(listener: SpeechListener<\"result\"> | null) {\n this._setListeners(\"result\", listener, this.#onresult);\n this.#onresult = listener;\n }\n /** Fired when the speech recognition service returns a result —\n * a word or phrase has been positively recognized and this has been communicated back to the app. */\n get onresult() {\n return this.#onresult;\n }\n\n #onnomatch: SpeechListener<\"nomatch\"> | null = null;\n set onnomatch(listener: SpeechListener<\"nomatch\"> | null) {\n this._setListeners(\"nomatch\", listener, this.#onnomatch);\n this.#onnomatch = listener;\n }\n /** Fired when the speech recognition service returns a final result with no significant recognition. */\n get onnomatch() {\n return this.#onnomatch;\n }\n\n #onspeechstart: SpeechListener<\"speechstart\"> | null = null;\n set onspeechstart(listener: SpeechListener<\"speechstart\"> | null) {\n this._setListeners(\"speechstart\", listener, this.#onspeechstart);\n this.#onspeechstart = listener;\n }\n /** Fired when the speech recognition service returns a final result with no significant recognition. */\n get onspeechstart() {\n return this.#onspeechstart;\n }\n\n #onspeechend: SpeechListener<\"speechend\"> | null = null;\n set onspeechend(listener: SpeechListener<\"speechend\"> | null) {\n this._setListeners(\"speechend\", listener, this.#onspeechend);\n this.#onspeechend = listener;\n }\n /** Fired when the speech recognition service returns a final result with no significant recognition. */\n get onspeechend() {\n return this.#onspeechend;\n }\n\n #onaudiostart: SpeechListener<\"audiostart\"> | null = null;\n set onaudiostart(listener: SpeechListener<\"audiostart\"> | null) {\n this._setListeners(\"audiostart\", listener, this.#onaudiostart);\n this.#onaudiostart = listener;\n }\n /** Fired when the user agent has started to capture audio. */\n get onaudiostart() {\n return this.#onaudiostart;\n }\n\n #onaudioend: SpeechListener<\"audioend\"> | null = null;\n set onaudioend(listener: SpeechListener<\"audioend\"> | null) {\n this._setListeners(\"audioend\", listener, this.#onaudioend);\n this.#onaudioend = listener;\n }\n /** Fired when the user agent has finished capturing audio. */\n get onaudioend() {\n return this.#onaudioend;\n }\n\n /** [TODO] */\n onsoundend: ((this: SpeechRecognition, ev: Event) => any) | null = null;\n /** [TODO] */\n onsoundstart: ((this: SpeechRecognition, ev: Event) => any) | null = null;\n\n addEventListener<K extends keyof SpeechRecognitionEventMap>(\n type: K,\n listener: SpeechListener<K>,\n options?: boolean | AddEventListenerOptions,\n ): void {\n const capture = typeof options === \"boolean\" ? options : !!options?.capture;\n if (\n this.#subscriptions.some(\n (entry) =>\n entry.type === type &&\n entry.listener === listener &&\n entry.capture === capture,\n )\n ) {\n return;\n }\n\n const once = typeof options === \"object\" && options.once;\n\n // If the user opts in to only listening once,\n // wrap the listener in a function that removes the listener\n const wrappedListener = once\n ? (((ev) => {\n // Remove before invoking the callback so nested delivery and\n // registrations made inside the callback keep their own lifetime.\n this.removeEventListener(type, listener, capture);\n listener.call(this, ev);\n }) as SpeechListener<K>)\n : listener;\n\n // Enhance the native listener with any necessary polyfills\n const enhancedEvent: NativeEventAndListener<K> =\n WebListenerTransformers[type]?.(this, wrappedListener) ??\n stubEvent(\n type,\n this,\n wrappedListener as (this: SpeechRecognition, ev: Event) => unknown,\n );\n\n const subscription = ExpoSpeechRecognitionModule.addListener(\n enhancedEvent.eventName,\n // @ts-expect-error\n enhancedEvent.nativeListener,\n );\n\n this.#subscriptions.push({ type, listener, capture, subscription });\n }\n\n removeEventListener<K extends keyof SpeechRecognitionEventMap>(\n type: K,\n listener: (\n this: SpeechRecognition,\n ev: SpeechRecognitionEventMap[K],\n ) => any,\n options?: boolean | EventListenerOptions | undefined,\n ): void {\n const capture = typeof options === \"boolean\" ? options : !!options?.capture;\n const index = this.#subscriptions.findIndex(\n (entry) =>\n entry.type === type &&\n entry.listener === listener &&\n entry.capture === capture,\n );\n if (index !== -1) {\n const [registration] = this.#subscriptions.splice(index, 1);\n registration?.subscription.remove();\n }\n }\n\n dispatchEvent(event: Event): boolean {\n throw new Error(\"Method not implemented.\");\n }\n}\n\n/**\n * This class is just a polyfill and does nothing on Android/iOS\n */\nexport class ExpoWebSpeechGrammarList implements SpeechGrammarList {\n get length() {\n return this.#grammars.length;\n }\n #grammars: ExpoWebSpeechGrammar[] = [];\n [index: number]: SpeechGrammar; // Indexer property\n\n addFromURI(src: string, weight?: number | undefined): void {\n // todo\n }\n\n item(index: number): ExpoWebSpeechGrammar {\n return this.#grammars[index]!;\n }\n\n addFromString = (grammar: string, weight?: number) => {\n // TODO: parse grammar to html entities (data:application/xml,....)\n this.#grammars.push(new ExpoWebSpeechGrammar(grammar, weight));\n // Set key on this object for compatibility with web SpeechGrammarList API\n this[this.length - 1] = this.#grammars[this.length - 1]!;\n };\n}\n\nexport class ExpoWebSpeechGrammar implements SpeechGrammar {\n src = \"\";\n weight = 1;\n\n constructor(src: string, weight?: number) {\n this.src = src;\n this.weight = weight ?? 1;\n }\n}\n\nclass ExpoSpeechRecognitionResultList implements SpeechRecognitionResultList {\n #results: ExpoSpeechRecognitionResult[] = [];\n\n [Symbol.iterator](): ArrayIterator<ExpoSpeechRecognitionResult> {\n return this.#results[\n Symbol.iterator\n ]() as ArrayIterator<ExpoSpeechRecognitionResult>;\n }\n length: number;\n item(index: number): SpeechRecognitionResult {\n return this.#results[index]!;\n }\n [index: number]: SpeechRecognitionResult;\n\n constructor(results: ExpoSpeechRecognitionResult[]) {\n this.#results = results;\n this.length = results.length;\n for (let i = 0; i < this.#results.length; i++) {\n this[i] = this.#results[i]!;\n }\n }\n}\n\nclass ExpoSpeechRecognitionResult implements SpeechRecognitionResult {\n #alternatives: ExpoSpeechRecognitionAlternative[] = [];\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SpeechRecognitionResult/isFinal) */\n readonly isFinal: boolean;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SpeechRecognitionResult/length) */\n length: number;\n /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/SpeechRecognitionResult/item) */\n item(index: number): SpeechRecognitionAlternative {\n return this.#alternatives[index]!;\n }\n [index: number]: SpeechRecognitionAlternative;\n [Symbol.iterator](): ArrayIterator<SpeechRecognitionAlternative> {\n return this.#alternatives[\n Symbol.iterator\n ]() as ArrayIterator<SpeechRecognitionAlternative>;\n }\n\n constructor(\n isFinal: boolean,\n alternatives: ExpoSpeechRecognitionAlternative[],\n ) {\n this.isFinal = isFinal;\n this.length = alternatives.length;\n this.#alternatives = alternatives;\n for (let i = 0; i < alternatives.length; i++) {\n this[i] = alternatives[i]!;\n }\n }\n}\n\nclass ExpoSpeechRecognitionAlternative implements SpeechRecognitionAlternative {\n confidence: number;\n transcript: string;\n\n constructor(confidence: number, transcript: string) {\n this.confidence = confidence;\n this.transcript = transcript;\n }\n}\n"]}
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-speech-recognition",
|
|
3
|
-
"version": "58.
|
|
3
|
+
"version": "58.1.1",
|
|
4
4
|
"description": "Speech Recognition for React Native Expo projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"@changesets/cli": "^2.31.0",
|
|
45
45
|
"@types/dom-speech-recognition": "^0.0.11",
|
|
46
46
|
"@types/react": "~19.3.0",
|
|
47
|
-
"expo": "~58.0
|
|
47
|
+
"expo": "~58.1.0",
|
|
48
48
|
"expo-module-scripts": "^56.0.3",
|
|
49
49
|
"globals": "17.6.0",
|
|
50
50
|
"react": "^19.3.0",
|
|
51
|
-
"react-native": "^0.88.
|
|
51
|
+
"react-native": "^0.88.1",
|
|
52
52
|
"typescript": "~6.0.3",
|
|
53
53
|
"typescript-eslint": "8.59.0"
|
|
54
54
|
},
|
|
@@ -208,8 +208,12 @@ export class ExpoWebSpeechRecognition implements SpeechRecognition {
|
|
|
208
208
|
*/
|
|
209
209
|
androidRecognitionServicePackage: ExpoSpeechRecognitionOptions["androidRecognitionServicePackage"];
|
|
210
210
|
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
#subscriptions: {
|
|
212
|
+
type: keyof SpeechRecognitionEventMap;
|
|
213
|
+
listener: SpeechListener<any>;
|
|
214
|
+
capture: boolean;
|
|
215
|
+
subscription: EventSubscription;
|
|
216
|
+
}[] = [];
|
|
213
217
|
|
|
214
218
|
start() {
|
|
215
219
|
ExpoSpeechRecognitionModule.requestPermissionsAsync().then(() => {
|
|
@@ -356,18 +360,28 @@ export class ExpoWebSpeechRecognition implements SpeechRecognition {
|
|
|
356
360
|
listener: SpeechListener<K>,
|
|
357
361
|
options?: boolean | AddEventListenerOptions,
|
|
358
362
|
): void {
|
|
363
|
+
const capture = typeof options === "boolean" ? options : !!options?.capture;
|
|
364
|
+
if (
|
|
365
|
+
this.#subscriptions.some(
|
|
366
|
+
(entry) =>
|
|
367
|
+
entry.type === type &&
|
|
368
|
+
entry.listener === listener &&
|
|
369
|
+
entry.capture === capture,
|
|
370
|
+
)
|
|
371
|
+
) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
|
|
359
375
|
const once = typeof options === "object" && options.once;
|
|
360
376
|
|
|
361
377
|
// If the user opts in to only listening once,
|
|
362
378
|
// wrap the listener in a function that removes the listener
|
|
363
379
|
const wrappedListener = once
|
|
364
380
|
? (((ev) => {
|
|
381
|
+
// Remove before invoking the callback so nested delivery and
|
|
382
|
+
// registrations made inside the callback keep their own lifetime.
|
|
383
|
+
this.removeEventListener(type, listener, capture);
|
|
365
384
|
listener.call(this, ev);
|
|
366
|
-
// remove the listeners from the map
|
|
367
|
-
for (const sub of this.#subscriptionMap.get(listener) ?? []) {
|
|
368
|
-
sub.remove();
|
|
369
|
-
}
|
|
370
|
-
this.#subscriptionMap.delete(listener);
|
|
371
385
|
}) as SpeechListener<K>)
|
|
372
386
|
: listener;
|
|
373
387
|
|
|
@@ -386,9 +400,7 @@ export class ExpoWebSpeechRecognition implements SpeechRecognition {
|
|
|
386
400
|
enhancedEvent.nativeListener,
|
|
387
401
|
);
|
|
388
402
|
|
|
389
|
-
|
|
390
|
-
// This is keyed by the listener function so we can remove all subscriptions for a given listener
|
|
391
|
-
this.#subscriptionMap.set(listener, [subscription]);
|
|
403
|
+
this.#subscriptions.push({ type, listener, capture, subscription });
|
|
392
404
|
}
|
|
393
405
|
|
|
394
406
|
removeEventListener<K extends keyof SpeechRecognitionEventMap>(
|
|
@@ -399,12 +411,16 @@ export class ExpoWebSpeechRecognition implements SpeechRecognition {
|
|
|
399
411
|
) => any,
|
|
400
412
|
options?: boolean | EventListenerOptions | undefined,
|
|
401
413
|
): void {
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
414
|
+
const capture = typeof options === "boolean" ? options : !!options?.capture;
|
|
415
|
+
const index = this.#subscriptions.findIndex(
|
|
416
|
+
(entry) =>
|
|
417
|
+
entry.type === type &&
|
|
418
|
+
entry.listener === listener &&
|
|
419
|
+
entry.capture === capture,
|
|
420
|
+
);
|
|
421
|
+
if (index !== -1) {
|
|
422
|
+
const [registration] = this.#subscriptions.splice(index, 1);
|
|
423
|
+
registration?.subscription.remove();
|
|
408
424
|
}
|
|
409
425
|
}
|
|
410
426
|
|