expo-speech-recognition 0.2.20 → 0.2.22
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/LICENSE +21 -0
- package/README.md +123 -47
- package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechRecognitionModule.kt +4 -0
- package/android/src/main/java/expo/modules/speechrecognition/ExpoSpeechService.kt +11 -2
- package/app.plugin.js +18 -12
- package/build/ExpoSpeechRecognitionModule.d.ts +2 -40
- package/build/ExpoSpeechRecognitionModule.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.js +1 -0
- package/build/ExpoSpeechRecognitionModule.js.map +1 -1
- package/build/ExpoSpeechRecognitionModule.types.d.ts +65 -43
- package/build/ExpoSpeechRecognitionModule.types.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.types.js.map +1 -1
- package/build/ExpoSpeechRecognitionModule.web.d.ts.map +1 -1
- package/build/ExpoSpeechRecognitionModule.web.js +5 -4
- package/build/ExpoSpeechRecognitionModule.web.js.map +1 -1
- package/build/ExpoWebSpeechRecognition.d.ts +1 -1
- package/build/ExpoWebSpeechRecognition.d.ts.map +1 -1
- package/build/ExpoWebSpeechRecognition.js +2 -2
- package/build/ExpoWebSpeechRecognition.js.map +1 -1
- package/build/index.d.ts +14 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -0
- package/build/index.js.map +1 -1
- package/build/useSpeechRecognitionEvent.d.ts +1 -1
- package/build/useSpeechRecognitionEvent.d.ts.map +1 -1
- package/build/useSpeechRecognitionEvent.js +1 -1
- package/build/useSpeechRecognitionEvent.js.map +1 -1
- package/ios/ExpoSpeechRecognitionModule.swift +6 -2
- package/ios/ExpoSpeechRecognizer.swift +0 -1
- package/package.json +1 -1
- package/src/ExpoSpeechRecognitionModule.ts +3 -1
- package/src/ExpoSpeechRecognitionModule.types.ts +76 -45
- package/src/ExpoSpeechRecognitionModule.web.ts +8 -12
- package/src/ExpoWebSpeechRecognition.ts +6 -9
- package/src/index.ts +16 -0
- package/src/useSpeechRecognitionEvent.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoWebSpeechRecognition.js","sourceRoot":"","sources":["../src/ExpoWebSpeechRecognition.ts"],"names":[],"mappings":"AAEA,wFAAwF;AACxF,sDAAsD;AACtD,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,+BAA+B,CAAC;AAMvC,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,IAAI;IACpB,WAAW,EAAE,CAAC;IACd,wBAAwB,EAAE,IAAI;IAC9B,eAAe,EAAE,IAAI;IACrB,MAAM;IACN,SAAS,EAAE,CAAC;IACZ,IAAI,EAAE,EAAE;IACR,YAAY,EAAE,KAAK;IACnB,WAAW,EAAE,KAAK;IAClB,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,IAAI;CAChB,CAAC,CAAC;AAYH,SAAS,SAAS,CAChB,SAAY,EACZ,QAAkC,EAClC,QAAyD;IAEzD,OAAO;QACL,SAAS;QACT,cAAc,EAAE,CAAC,WAAW,EAAE,EAAE,CAC9B,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;KACrD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,uBAAuB,GAQzB;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,MAAM,2BAA2B;IAC/B,aAAa,GAAuC,EAAE,CAAC;IACvD,kGAAkG;IACzF,OAAO,CAAU;IAC1B,iGAAiG;IACjG,MAAM,CAAS;IACf,+FAA+F;IAC/F,IAAI,CAAC,KAAa;QAChB,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAED,CAAC,MAAM,CAAC,QAAQ,CAAC;QACf,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC/C,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,CAAC,CAAC;QAC5B,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 type { Subscription } from \"expo-modules-core\";\n\n// Import the native module. On web, it will be resolved to ExpoSpeechRecognition.web.ts\n// and on native platforms to ExpoSpeechRecognition.ts\nimport {\n ExpoSpeechRecognitionModule,\n ExpoSpeechRecognitionModuleEmitter,\n} 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 });\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 });\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\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<Function, Subscription[]> = 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: (\n this: SpeechRecognition,\n ev: SpeechRecognitionEventMap[K],\n ) => any,\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 this.#subscriptionMap.get(listener)?.forEach((sub) => {\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 = ExpoSpeechRecognitionModuleEmitter.addListener(\n enhancedEvent.eventName,\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: string = \"\";\n weight: number = 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](): IterableIterator<ExpoSpeechRecognitionResult> {\n return this.#results[Symbol.iterator]();\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](): IterableIterator<SpeechRecognitionAlternative> {\n return this.#alternatives[Symbol.iterator]();\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":"AAEA,wFAAwF;AACxF,sDAAsD;AACtD,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,+BAA+B,CAAC;AAMvC,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEtB,MAAM,eAAe,GAAG,CAAC,MAAmB,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EhD,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,CAAC,CAAC;QAC5B,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 type { Subscription } from \"expo-modules-core\";\n\n// Import the native module. On web, it will be resolved to ExpoSpeechRecognition.web.ts\n// and on native platforms to ExpoSpeechRecognition.ts\nimport {\n ExpoSpeechRecognitionModule,\n ExpoSpeechRecognitionModuleEmitter,\n} 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 });\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 });\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\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>, Subscription[]> = 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 = ExpoSpeechRecognitionModuleEmitter.addListener(\n enhancedEvent.eventName,\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](): IterableIterator<ExpoSpeechRecognitionResult> {\n return this.#results[Symbol.iterator]();\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](): IterableIterator<SpeechRecognitionAlternative> {\n return this.#alternatives[Symbol.iterator]();\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/build/index.d.ts
CHANGED
|
@@ -21,6 +21,19 @@ export declare const getAudioSessionCategoryAndOptionsIOS: () => {
|
|
|
21
21
|
export declare const setAudioSessionActiveIOS: (value: boolean, options?: {
|
|
22
22
|
notifyOthersOnDeactivation: boolean;
|
|
23
23
|
}) => void;
|
|
24
|
+
export declare const androidTriggerOfflineModelDownload: (options: {
|
|
25
|
+
locale: string;
|
|
26
|
+
}) => Promise<{
|
|
27
|
+
status: "download_success" | "opened_dialog" | "download_canceled";
|
|
28
|
+
message: string;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const isRecognitionAvailable: () => boolean;
|
|
31
|
+
export declare const getDefaultRecognitionService: () => {
|
|
32
|
+
packageName: string;
|
|
33
|
+
};
|
|
34
|
+
export declare const getAssistantService: () => {
|
|
35
|
+
packageName: string;
|
|
36
|
+
};
|
|
24
37
|
export declare const addSpeechRecognitionListener: <T extends keyof ExpoSpeechRecognitionNativeEventMap>(eventName: T, listener: (ev: ExpoSpeechRecognitionNativeEventMap[T]) => void) => import("expo-modules-core").Subscription;
|
|
25
|
-
export { type ExpoSpeechRecognitionOptions, type AndroidIntentOptions, type ExpoSpeechRecognitionNativeEventMap, type AVAudioSessionCategoryOptionsValue, type AVAudioSessionModeValue, type AVAudioSessionCategoryValue, type AudioEncodingAndroidValue, type AudioSourceOptions, type RecordingOptions, type IOSTaskHintValue, type SetCategoryOptions, type ExpoSpeechRecognitionErrorCode, } from "./ExpoSpeechRecognitionModule.types";
|
|
38
|
+
export { type ExpoSpeechRecognitionOptions, type AndroidIntentOptions, type ExpoSpeechRecognitionNativeEventMap, type AVAudioSessionCategoryOptionsValue, type AVAudioSessionModeValue, type AVAudioSessionCategoryValue, type AudioEncodingAndroidValue, type AudioSourceOptions, type RecordingOptions, type IOSTaskHintValue, type SetCategoryOptions, type ExpoSpeechRecognitionErrorCode, type ExpoSpeechRecognitionErrorEvent, type ExpoSpeechRecognitionResultEvent, type ExpoSpeechRecognitionResult, type ExpoSpeechRecognitionResultSegment, } from "./ExpoSpeechRecognitionModule.types";
|
|
26
39
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,qCAAqC,CAAC;AAG/F,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,EACL,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,kCAAkC,EAClC,oCAAoC,EACpC,oBAAoB,EACpB,WAAW,GACZ,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,mBAAmB,aAAc;IAC5C,gCAAgC,CAAC,EAAE,MAAM,CAAC;CAC3C;;;EAAmE,CAAC;AAErE,eAAO,MA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BACiB,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,GACvC,CAAC,SAAS,MAAM,mCAAmC,aAExC,CAAC,YACF,CAAC,EAAE,EAAE,mCAAmC,CAAC,CAAC,CAAC,KAAK,IAAI,6CACQ,CAAC;AAEzE,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,oBAAoB,EACzB,KAAK,mCAAmC,EACxC,KAAK,kCAAkC,EACvC,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAChC,KAAK,yBAAyB,EAC9B,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,8BAA8B,EACnC,KAAK,+BAA+B,EACpC,KAAK,gCAAgC,EACrC,KAAK,2BAA2B,EAChC,KAAK,kCAAkC,GACxC,MAAM,qCAAqC,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -14,5 +14,9 @@ export const supportsRecording = ExpoSpeechRecognitionModule.supportsRecording;
|
|
|
14
14
|
export const setCategoryIOS = ExpoSpeechRecognitionModule.setCategoryIOS;
|
|
15
15
|
export const getAudioSessionCategoryAndOptionsIOS = ExpoSpeechRecognitionModule.getAudioSessionCategoryAndOptionsIOS;
|
|
16
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;
|
|
17
21
|
export const addSpeechRecognitionListener = (eventName, listener) => ExpoSpeechRecognitionModuleEmitter.addListener(eventName, listener);
|
|
18
22
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,+BAA+B,CAAC;AAGvC,oCAAoC;AACpC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAEpC,gBAAgB;AAChB,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,+BAA+B,CAAC;AAEvC,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,GACZ,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,4BAA4B,GAAG,CAG1C,SAAY,EACZ,QAA8D,EAC9D,EAAE,CAAC,kCAAkC,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["import {\n ExpoSpeechRecognitionModule,\n ExpoSpeechRecognitionModuleEmitter,\n} from \"./ExpoSpeechRecognitionModule\";\nimport type { ExpoSpeechRecognitionNativeEventMap } from \"./ExpoSpeechRecognitionModule.types\";\n\n// Export the SpeechRecognition APIs\nexport {\n ExpoWebSpeechRecognition,\n ExpoWebSpeechGrammar,\n ExpoWebSpeechGrammarList,\n} from \"./ExpoWebSpeechRecognition\";\n\n// Native module\nexport {\n ExpoSpeechRecognitionModule,\n ExpoSpeechRecognitionModuleEmitter,\n} 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} 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 addSpeechRecognitionListener = <\n T extends keyof ExpoSpeechRecognitionNativeEventMap,\n>(\n eventName: T,\n listener: (ev: ExpoSpeechRecognitionNativeEventMap[T]) => void,\n) => ExpoSpeechRecognitionModuleEmitter.addListener(eventName, listener);\n\nexport {\n type ExpoSpeechRecognitionOptions,\n type AndroidIntentOptions,\n type ExpoSpeechRecognitionNativeEventMap,\n type AVAudioSessionCategoryOptionsValue,\n type AVAudioSessionModeValue,\n type AVAudioSessionCategoryValue,\n type AudioEncodingAndroidValue,\n type AudioSourceOptions,\n type RecordingOptions,\n type IOSTaskHintValue,\n type SetCategoryOptions,\n type ExpoSpeechRecognitionErrorCode,\n} from \"./ExpoSpeechRecognitionModule.types\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,+BAA+B,CAAC;AAGvC,oCAAoC;AACpC,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAEpC,gBAAgB;AAChB,OAAO,EACL,2BAA2B,EAC3B,kCAAkC,GACnC,MAAM,+BAA+B,CAAC;AAEvC,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,GACZ,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,GAAG,CAG1C,SAAY,EACZ,QAA8D,EAC9D,EAAE,CAAC,kCAAkC,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["import {\n ExpoSpeechRecognitionModule,\n ExpoSpeechRecognitionModuleEmitter,\n} from \"./ExpoSpeechRecognitionModule\";\nimport type { ExpoSpeechRecognitionNativeEventMap } from \"./ExpoSpeechRecognitionModule.types\";\n\n// Export the SpeechRecognition APIs\nexport {\n ExpoWebSpeechRecognition,\n ExpoWebSpeechGrammar,\n ExpoWebSpeechGrammarList,\n} from \"./ExpoWebSpeechRecognition\";\n\n// Native module\nexport {\n ExpoSpeechRecognitionModule,\n ExpoSpeechRecognitionModuleEmitter,\n} 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} 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 T extends keyof ExpoSpeechRecognitionNativeEventMap,\n>(\n eventName: T,\n listener: (ev: ExpoSpeechRecognitionNativeEventMap[T]) => void,\n) => ExpoSpeechRecognitionModuleEmitter.addListener(eventName, listener);\n\nexport {\n type ExpoSpeechRecognitionOptions,\n type AndroidIntentOptions,\n type ExpoSpeechRecognitionNativeEventMap,\n type AVAudioSessionCategoryOptionsValue,\n type AVAudioSessionModeValue,\n type AVAudioSessionCategoryValue,\n type AudioEncodingAndroidValue,\n type AudioSourceOptions,\n type RecordingOptions,\n type IOSTaskHintValue,\n type SetCategoryOptions,\n type ExpoSpeechRecognitionErrorCode,\n type ExpoSpeechRecognitionErrorEvent,\n type ExpoSpeechRecognitionResultEvent,\n type ExpoSpeechRecognitionResult,\n type ExpoSpeechRecognitionResultSegment,\n} from \"./ExpoSpeechRecognitionModule.types\";\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExpoSpeechRecognitionNativeEventMap } from "./ExpoSpeechRecognitionModule.types";
|
|
1
|
+
import type { ExpoSpeechRecognitionNativeEventMap } from "./ExpoSpeechRecognitionModule.types";
|
|
2
2
|
/**
|
|
3
3
|
* This hook allows you to listen to native events emitted by the `ExpoSpeechRecognitionModule`.
|
|
4
4
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSpeechRecognitionEvent.d.ts","sourceRoot":"","sources":["../src/useSpeechRecognitionEvent.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mCAAmC,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"useSpeechRecognitionEvent.d.ts","sourceRoot":"","sources":["../src/useSpeechRecognitionEvent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,qCAAqC,CAAC;AAE/F;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,CAAC,SAAS,MAAM,mCAAmC,EAEnD,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,CAAC,EAAE,EAAE,mCAAmC,CAAC,CAAC,CAAC,KAAK,IAAI,QAa/D"}
|
|
@@ -15,6 +15,6 @@ export function useSpeechRecognitionEvent(eventName, listener) {
|
|
|
15
15
|
const handler = listenerRef.current;
|
|
16
16
|
const subscription = ExpoSpeechRecognitionModuleEmitter.addListener(eventName, handler);
|
|
17
17
|
return subscription.remove;
|
|
18
|
-
}, [eventName
|
|
18
|
+
}, [eventName]);
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=useSpeechRecognitionEvent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSpeechRecognitionEvent.js","sourceRoot":"","sources":["../src/useSpeechRecognitionEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AAGnF;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CAGvC,SAAY,EACZ,QAA8D;IAE9D,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IAE/B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC;QACpC,MAAM,YAAY,GAAG,kCAAkC,CAAC,WAAW,CACjE,SAAS,EACT,OAAO,CACR,CAAC;QACF,OAAO,YAAY,CAAC,MAAM,CAAC;IAC7B,CAAC,EAAE,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"useSpeechRecognitionEvent.js","sourceRoot":"","sources":["../src/useSpeechRecognitionEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,kCAAkC,EAAE,MAAM,+BAA+B,CAAC;AAGnF;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CAGvC,SAAY,EACZ,QAA8D;IAE9D,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IAE/B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC;QACpC,MAAM,YAAY,GAAG,kCAAkC,CAAC,WAAW,CACjE,SAAS,EACT,OAAO,CACR,CAAC;QACF,OAAO,YAAY,CAAC,MAAM,CAAC;IAC7B,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import { useEffect, useRef } from \"react\";\nimport { ExpoSpeechRecognitionModuleEmitter } from \"./ExpoSpeechRecognitionModule\";\nimport type { ExpoSpeechRecognitionNativeEventMap } from \"./ExpoSpeechRecognitionModule.types\";\n\n/**\n * This hook allows you to listen to native events emitted by the `ExpoSpeechRecognitionModule`.\n *\n * Note: this is not the same as the `SpeechRecognition` event listener on the web speech API.\n *\n * @param eventName The name of the event to listen to\n * @param listener The listener function to call when the event is emitted\n */\nexport function useSpeechRecognitionEvent<\n K extends keyof ExpoSpeechRecognitionNativeEventMap,\n>(\n eventName: K,\n listener: (ev: ExpoSpeechRecognitionNativeEventMap[K]) => void,\n) {\n const listenerRef = useRef(listener);\n listenerRef.current = listener;\n\n useEffect(() => {\n const handler = listenerRef.current;\n const subscription = ExpoSpeechRecognitionModuleEmitter.addListener(\n eventName,\n handler,\n );\n return subscription.remove;\n }, [eventName]);\n}\n"]}
|
|
@@ -279,7 +279,11 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
Function("supportsRecording") { () -> Bool in
|
|
282
|
-
|
|
282
|
+
return true
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
Function("isRecognitionAvailable") { () -> Bool in
|
|
286
|
+
let recognizer = SFSpeechRecognizer()
|
|
283
287
|
return recognizer?.isAvailable ?? false
|
|
284
288
|
}
|
|
285
289
|
|
|
@@ -419,7 +423,7 @@ public class ExpoSpeechRecognitionModule: Module {
|
|
|
419
423
|
|
|
420
424
|
if isFinal && results.isEmpty {
|
|
421
425
|
// https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/nomatch_event
|
|
422
|
-
// The nomatch event of the Web Speech API is
|
|
426
|
+
// The nomatch event of the Web Speech API is fired
|
|
423
427
|
// when the speech recognition service returns a final result with no significant recognition.
|
|
424
428
|
sendEvent("nomatch")
|
|
425
429
|
return
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ import type { ExpoSpeechRecognitionModuleType } from "./ExpoSpeechRecognitionMod
|
|
|
11
11
|
const ExpoSpeechRecognitionNativeModule =
|
|
12
12
|
requireNativeModule<ExpoSpeechRecognitionModuleType>("ExpoSpeechRecognition");
|
|
13
13
|
|
|
14
|
-
export const ExpoSpeechRecognitionModule = {
|
|
14
|
+
export const ExpoSpeechRecognitionModule: ExpoSpeechRecognitionModuleType = {
|
|
15
15
|
...ExpoSpeechRecognitionNativeModule,
|
|
16
16
|
// Avoid any function bindings when calling the native module
|
|
17
17
|
stop: () => ExpoSpeechRecognitionNativeModule.stop(),
|
|
@@ -31,6 +31,8 @@ export const ExpoSpeechRecognitionModule = {
|
|
|
31
31
|
ExpoSpeechRecognitionNativeModule.supportsOnDeviceRecognition(),
|
|
32
32
|
supportsRecording: () =>
|
|
33
33
|
ExpoSpeechRecognitionNativeModule.supportsRecording(),
|
|
34
|
+
isRecognitionAvailable: () =>
|
|
35
|
+
ExpoSpeechRecognitionNativeModule.isRecognitionAvailable(),
|
|
34
36
|
};
|
|
35
37
|
|
|
36
38
|
export const ExpoSpeechRecognitionModuleEmitter = new EventEmitter(
|
|
@@ -14,6 +14,48 @@ import type {
|
|
|
14
14
|
export type AVAudioSessionCategoryValue =
|
|
15
15
|
(typeof AVAudioSessionCategory)[keyof typeof AVAudioSessionCategory];
|
|
16
16
|
|
|
17
|
+
export type ExpoSpeechRecognitionResult = {
|
|
18
|
+
transcript: string;
|
|
19
|
+
/**
|
|
20
|
+
* Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating transcript confidence.
|
|
21
|
+
*/
|
|
22
|
+
confidence: number;
|
|
23
|
+
/**
|
|
24
|
+
* An array of transcription segments that represent the parts of the transcription, as identified by the speech recognizer.
|
|
25
|
+
*
|
|
26
|
+
* Notes for Android:
|
|
27
|
+
*
|
|
28
|
+
* - This is only available for SDK 34+ (Android 14+)
|
|
29
|
+
* - This is only verified to work with the `com.google.android.as` service (using on device speech recognition)
|
|
30
|
+
* - Segments are only available during the final result
|
|
31
|
+
* - The segment parts are split up by words.
|
|
32
|
+
* - The segments are only available for the first transcript
|
|
33
|
+
* - Segment confidences currently return as -1 (unavailable)
|
|
34
|
+
*
|
|
35
|
+
* Notes for iOS:
|
|
36
|
+
*
|
|
37
|
+
* - The confidence value will be 0 on partial results
|
|
38
|
+
*/
|
|
39
|
+
segments: ExpoSpeechRecognitionResultSegment[];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type ExpoSpeechRecognitionResultSegment = {
|
|
43
|
+
/** The start timestamp of the utterance, e.g. 1000 */
|
|
44
|
+
startTimeMillis: number;
|
|
45
|
+
/** The end timestamp of the utterance, e.g. 1500 */
|
|
46
|
+
endTimeMillis: number;
|
|
47
|
+
/** The text portion of the transcript, e.g. "Hello world" */
|
|
48
|
+
segment: string;
|
|
49
|
+
/** Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating the confidence of the specific segment */
|
|
50
|
+
confidence: number;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Fired when there's a speech result. The result may be partial or final */
|
|
54
|
+
export type ExpoSpeechRecognitionResultEvent = {
|
|
55
|
+
isFinal: boolean;
|
|
56
|
+
results: ExpoSpeechRecognitionResult[];
|
|
57
|
+
};
|
|
58
|
+
|
|
17
59
|
export type ExpoSpeechRecognitionErrorCode =
|
|
18
60
|
/** The user called `ExpoSpeechRecognitionModule.abort()`. */
|
|
19
61
|
| "aborted"
|
|
@@ -35,53 +77,23 @@ export type ExpoSpeechRecognitionErrorCode =
|
|
|
35
77
|
/** The recognizer is busy and cannot accept any new recognition requests. */
|
|
36
78
|
| "busy"
|
|
37
79
|
/** (Android only) An unknown client-side error occurred. */
|
|
38
|
-
| "client"
|
|
80
|
+
| "client"
|
|
81
|
+
/** (Android) No speech input. */
|
|
82
|
+
| "speech-timeout"
|
|
83
|
+
/** (Android) Unknown error */
|
|
84
|
+
| "unknown";
|
|
85
|
+
|
|
86
|
+
export type ExpoSpeechRecognitionErrorEvent = {
|
|
87
|
+
error: ExpoSpeechRecognitionErrorCode;
|
|
88
|
+
message: string;
|
|
89
|
+
};
|
|
39
90
|
|
|
40
91
|
/**
|
|
41
92
|
* Events that are dispatched from the native side
|
|
42
93
|
*/
|
|
43
94
|
export type ExpoSpeechRecognitionNativeEventMap = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
isFinal: boolean;
|
|
47
|
-
results: {
|
|
48
|
-
transcript: string;
|
|
49
|
-
/**
|
|
50
|
-
* Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating transcript confidence.
|
|
51
|
-
*/
|
|
52
|
-
confidence: number;
|
|
53
|
-
/**
|
|
54
|
-
* An array of transcription segments that represent the parts of the transcription, as identified by the speech recognizer.
|
|
55
|
-
*
|
|
56
|
-
* Notes for Android:
|
|
57
|
-
*
|
|
58
|
-
* - This is only available for SDK 34+ (Android 14+)
|
|
59
|
-
* - This is only verified to work with the `com.google.android.as` service (using on device speech recognition)
|
|
60
|
-
* - Segments are only available during the final result
|
|
61
|
-
* - The segment parts are split up by words.
|
|
62
|
-
* - The segments are only available for the first transcript
|
|
63
|
-
* - Segment confidences currently return as -1 (unavailable)
|
|
64
|
-
*
|
|
65
|
-
* Notes for iOS:
|
|
66
|
-
*
|
|
67
|
-
* - The confidence value will be 0 on partial results
|
|
68
|
-
*/
|
|
69
|
-
segments: {
|
|
70
|
-
/** The start timestamp of the utterance, e.g. 1000 */
|
|
71
|
-
startTimeMillis: number;
|
|
72
|
-
/** The end timestamp of the utterance, e.g. 1500 */
|
|
73
|
-
endTimeMillis: number;
|
|
74
|
-
/** The text portion of the transcript, e.g. "Hello world" */
|
|
75
|
-
segment: string;
|
|
76
|
-
/** Value ranging between between 0.0, 1.0, and -1 (unavailable) indicating the confidence of the specific segment */
|
|
77
|
-
confidence: number;
|
|
78
|
-
}[];
|
|
79
|
-
}[];
|
|
80
|
-
};
|
|
81
|
-
error: {
|
|
82
|
-
error: ExpoSpeechRecognitionErrorCode;
|
|
83
|
-
message: string;
|
|
84
|
-
};
|
|
95
|
+
result: ExpoSpeechRecognitionResultEvent;
|
|
96
|
+
error: ExpoSpeechRecognitionErrorEvent;
|
|
85
97
|
start: null;
|
|
86
98
|
speechstart: null;
|
|
87
99
|
speechend: null;
|
|
@@ -132,7 +144,13 @@ export type ExpoSpeechRecognitionOptions = {
|
|
|
132
144
|
* On iOS, this configures [`SFSpeechRecognitionRequest.contextualStrings`](https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/1649391-contextualstrings).
|
|
133
145
|
*/
|
|
134
146
|
contextualStrings?: string[];
|
|
135
|
-
/**
|
|
147
|
+
/**
|
|
148
|
+
* [Default: false] Continuous recognition.
|
|
149
|
+
*
|
|
150
|
+
* Not supported on Android 12 and below.
|
|
151
|
+
*
|
|
152
|
+
* If false on iOS, recognition will run until no speech is detected for 3 seconds.
|
|
153
|
+
*/
|
|
136
154
|
continuous?: boolean;
|
|
137
155
|
/** [Default: false] Prevent device from sending audio over the network. Only enabled if the device supports it.
|
|
138
156
|
*
|
|
@@ -527,7 +545,10 @@ export interface ExpoSpeechRecognitionModuleType extends NativeModule {
|
|
|
527
545
|
*
|
|
528
546
|
* @returns empty string if no service is found, or not Android
|
|
529
547
|
*/
|
|
530
|
-
getDefaultRecognitionService(): {
|
|
548
|
+
getDefaultRecognitionService(): {
|
|
549
|
+
/** e.g. "com.google.android.tts" or "com.google.android.googlequicksearchbox" */
|
|
550
|
+
packageName: string;
|
|
551
|
+
};
|
|
531
552
|
/**
|
|
532
553
|
* [Android only] Returns the default voice recognition service on the device.
|
|
533
554
|
*
|
|
@@ -535,7 +556,10 @@ export interface ExpoSpeechRecognitionModuleType extends NativeModule {
|
|
|
535
556
|
*
|
|
536
557
|
* @returns empty string if no service is found, or not Android
|
|
537
558
|
*/
|
|
538
|
-
getAssistantService(): {
|
|
559
|
+
getAssistantService(): {
|
|
560
|
+
/** e.g. "com.google.android.googlequicksearchbox" or "com.samsung.android.bixby.agent" */
|
|
561
|
+
packageName: string;
|
|
562
|
+
};
|
|
539
563
|
/**
|
|
540
564
|
* Whether the on-device speech recognition is available on the device.
|
|
541
565
|
*/
|
|
@@ -546,6 +570,13 @@ export interface ExpoSpeechRecognitionModuleType extends NativeModule {
|
|
|
546
570
|
* This mostly applies to Android devices, to check if it's greater than Android 13.
|
|
547
571
|
*/
|
|
548
572
|
supportsRecording(): boolean;
|
|
573
|
+
/**
|
|
574
|
+
* Whether on-device speech recognition is available.
|
|
575
|
+
*
|
|
576
|
+
* If this method returns false, `start()` will fail and emit an error event with the code `service-not-allowed` or `language-not-supported`.
|
|
577
|
+
*/
|
|
578
|
+
isRecognitionAvailable(): boolean;
|
|
579
|
+
|
|
549
580
|
/**
|
|
550
581
|
* Downloads the offline model for the specified locale.
|
|
551
582
|
* Note: this is only supported on Android 13 and above.
|
|
@@ -82,31 +82,19 @@ export const ExpoSpeechRecognitionModule: ExpoSpeechRecognitionModuleType = {
|
|
|
82
82
|
);
|
|
83
83
|
},
|
|
84
84
|
getSpeechRecognitionServices: () => {
|
|
85
|
-
console.warn(
|
|
86
|
-
"getSpeechRecognitionServices is not supported on web. Returning an empty array.",
|
|
87
|
-
);
|
|
88
85
|
return [] as string[];
|
|
89
86
|
},
|
|
90
87
|
getDefaultRecognitionService: () => {
|
|
91
|
-
console.warn(
|
|
92
|
-
"getDefaultRecognitionService is not supported on web. Returning an empty object.",
|
|
93
|
-
);
|
|
94
88
|
return {
|
|
95
89
|
packageName: "",
|
|
96
90
|
};
|
|
97
91
|
},
|
|
98
92
|
getAssistantService: () => {
|
|
99
|
-
console.warn(
|
|
100
|
-
"getAssistantService is not supported on web. Returning an empty object.",
|
|
101
|
-
);
|
|
102
93
|
return {
|
|
103
94
|
packageName: "",
|
|
104
95
|
};
|
|
105
96
|
},
|
|
106
97
|
supportsOnDeviceRecognition: () => {
|
|
107
|
-
console.warn(
|
|
108
|
-
"supportsOnDeviceRecognition is not supported on web. Returning false.",
|
|
109
|
-
);
|
|
110
98
|
return false;
|
|
111
99
|
},
|
|
112
100
|
supportsRecording: () => {
|
|
@@ -137,6 +125,13 @@ export const ExpoSpeechRecognitionModule: ExpoSpeechRecognitionModuleType = {
|
|
|
137
125
|
setAudioSessionActiveIOS: () => {
|
|
138
126
|
console.warn("setAudioSessionActiveIOS is not supported on web.");
|
|
139
127
|
},
|
|
128
|
+
isRecognitionAvailable: () => {
|
|
129
|
+
const hasSpeechRecognitionAPI =
|
|
130
|
+
typeof webkitSpeechRecognition !== "undefined" ||
|
|
131
|
+
typeof SpeechRecognition !== "undefined";
|
|
132
|
+
|
|
133
|
+
return hasSpeechRecognitionAPI;
|
|
134
|
+
},
|
|
140
135
|
};
|
|
141
136
|
|
|
142
137
|
/**
|
|
@@ -176,6 +171,7 @@ const webToNativeEventMap: {
|
|
|
176
171
|
start: (ev) => null,
|
|
177
172
|
soundend: (ev) => null,
|
|
178
173
|
};
|
|
174
|
+
|
|
179
175
|
export const ExpoSpeechRecognitionModuleEmitter = {
|
|
180
176
|
_nativeListeners: new Map() as Map<string, Set<(event: any) => void>>,
|
|
181
177
|
_clientListeners: new Map() as Map<
|
|
@@ -210,7 +210,7 @@ export class ExpoWebSpeechRecognition implements SpeechRecognition {
|
|
|
210
210
|
androidRecognitionServicePackage: ExpoSpeechRecognitionOptions["androidRecognitionServicePackage"];
|
|
211
211
|
|
|
212
212
|
// keyed by listener function
|
|
213
|
-
#subscriptionMap: Map<
|
|
213
|
+
#subscriptionMap: Map<SpeechListener<any>, Subscription[]> = new Map();
|
|
214
214
|
|
|
215
215
|
start() {
|
|
216
216
|
ExpoSpeechRecognitionModule.requestPermissionsAsync().then(() => {
|
|
@@ -354,10 +354,7 @@ export class ExpoWebSpeechRecognition implements SpeechRecognition {
|
|
|
354
354
|
|
|
355
355
|
addEventListener<K extends keyof SpeechRecognitionEventMap>(
|
|
356
356
|
type: K,
|
|
357
|
-
listener:
|
|
358
|
-
this: SpeechRecognition,
|
|
359
|
-
ev: SpeechRecognitionEventMap[K],
|
|
360
|
-
) => any,
|
|
357
|
+
listener: SpeechListener<K>,
|
|
361
358
|
options?: boolean | AddEventListenerOptions,
|
|
362
359
|
): void {
|
|
363
360
|
const once = typeof options === "object" && options.once;
|
|
@@ -368,9 +365,9 @@ export class ExpoWebSpeechRecognition implements SpeechRecognition {
|
|
|
368
365
|
? (((ev) => {
|
|
369
366
|
listener.call(this, ev);
|
|
370
367
|
// remove the listeners from the map
|
|
371
|
-
this.#subscriptionMap.get(listener)
|
|
368
|
+
for (const sub of this.#subscriptionMap.get(listener) ?? []) {
|
|
372
369
|
sub.remove();
|
|
373
|
-
}
|
|
370
|
+
}
|
|
374
371
|
this.#subscriptionMap.delete(listener);
|
|
375
372
|
}) as SpeechListener<K>)
|
|
376
373
|
: listener;
|
|
@@ -443,8 +440,8 @@ export class ExpoWebSpeechGrammarList implements SpeechGrammarList {
|
|
|
443
440
|
}
|
|
444
441
|
|
|
445
442
|
export class ExpoWebSpeechGrammar implements SpeechGrammar {
|
|
446
|
-
src
|
|
447
|
-
weight
|
|
443
|
+
src = "";
|
|
444
|
+
weight = 1;
|
|
448
445
|
|
|
449
446
|
constructor(src: string, weight?: number) {
|
|
450
447
|
this.src = src;
|
package/src/index.ts
CHANGED
|
@@ -51,6 +51,18 @@ export const getAudioSessionCategoryAndOptionsIOS =
|
|
|
51
51
|
export const setAudioSessionActiveIOS =
|
|
52
52
|
ExpoSpeechRecognitionModule.setAudioSessionActiveIOS;
|
|
53
53
|
|
|
54
|
+
export const androidTriggerOfflineModelDownload =
|
|
55
|
+
ExpoSpeechRecognitionModule.androidTriggerOfflineModelDownload;
|
|
56
|
+
|
|
57
|
+
export const isRecognitionAvailable =
|
|
58
|
+
ExpoSpeechRecognitionModule.isRecognitionAvailable;
|
|
59
|
+
|
|
60
|
+
export const getDefaultRecognitionService =
|
|
61
|
+
ExpoSpeechRecognitionModule.getDefaultRecognitionService;
|
|
62
|
+
|
|
63
|
+
export const getAssistantService =
|
|
64
|
+
ExpoSpeechRecognitionModule.getAssistantService;
|
|
65
|
+
|
|
54
66
|
export const addSpeechRecognitionListener = <
|
|
55
67
|
T extends keyof ExpoSpeechRecognitionNativeEventMap,
|
|
56
68
|
>(
|
|
@@ -71,4 +83,8 @@ export {
|
|
|
71
83
|
type IOSTaskHintValue,
|
|
72
84
|
type SetCategoryOptions,
|
|
73
85
|
type ExpoSpeechRecognitionErrorCode,
|
|
86
|
+
type ExpoSpeechRecognitionErrorEvent,
|
|
87
|
+
type ExpoSpeechRecognitionResultEvent,
|
|
88
|
+
type ExpoSpeechRecognitionResult,
|
|
89
|
+
type ExpoSpeechRecognitionResultSegment,
|
|
74
90
|
} from "./ExpoSpeechRecognitionModule.types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
2
|
import { ExpoSpeechRecognitionModuleEmitter } from "./ExpoSpeechRecognitionModule";
|
|
3
|
-
import { ExpoSpeechRecognitionNativeEventMap } from "./ExpoSpeechRecognitionModule.types";
|
|
3
|
+
import type { ExpoSpeechRecognitionNativeEventMap } from "./ExpoSpeechRecognitionModule.types";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* This hook allows you to listen to native events emitted by the `ExpoSpeechRecognitionModule`.
|
|
@@ -26,5 +26,5 @@ export function useSpeechRecognitionEvent<
|
|
|
26
26
|
handler,
|
|
27
27
|
);
|
|
28
28
|
return subscription.remove;
|
|
29
|
-
}, [eventName
|
|
29
|
+
}, [eventName]);
|
|
30
30
|
}
|