diff --git a/README.md b/README.md index 45b3c7d..b4afe84 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ expo-speech-recognition implements the iOS [`SFSpeechRecognizer`](https://develo - [getSpeechRecognitionServices()](#getspeechrecognitionservices-string-android-only) - [getDefaultRecognitionService()](#getdefaultrecognitionservice--packagename-string--android-only) - [getAssistantService()](#getassistantservice--packagename-string--android-only) - - [supportsOnDeviceRecognition()](#supportsondevicerecognition-boolean-android-only) + - [supportsOnDeviceRecognition()](#supportsondevicerecognition-boolean) - [supportsRecording()](#supportsrecording-boolean-android-only) - [androidTriggerOfflineModelDownload()](#androidtriggerofflinemodeldownload-locale-string--promise-status-opened_dialog--download_success--download_canceled-message-string-) - [setCategoryIOS()](#setcategoryios-void-ios-only) diff --git a/example/App.tsx b/example/App.tsx index 673ad65..134bdbc 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -18,13 +18,13 @@ import { type ExpoSpeechRecognitionOptions, type AndroidIntentOptions, useSpeechRecognitionEvent, - AudioEncodingAndroidValue, + type AudioEncodingAndroidValue, TaskHintIOS, AVAudioSessionCategory, type AVAudioSessionCategoryValue, AVAudioSessionCategoryOptions, type AVAudioSessionCategoryOptionsValue, - SetCategoryOptions, + type SetCategoryOptions, AVAudioSessionMode, type AVAudioSessionModeValue, ExpoWebSpeechRecognition, @@ -131,10 +131,6 @@ export default function App() { }); }; - const stopListening = () => { - ExpoSpeechRecognitionModule.stop(); - }; - return ( @@ -191,12 +187,12 @@ export default function App() { ExpoSpeechRecognitionModule.abort()} + onPress={ExpoSpeechRecognitionModule.abort} /> )} @@ -956,7 +952,7 @@ function WebSpeechAPIDemo() { transcript: string; }>(null); - const reconizer = useMemo(() => new ExpoWebSpeechRecognition(), []); + const recognizer = useMemo(() => new ExpoWebSpeechRecognition(), []); useEffect(() => { if (!listening) { @@ -982,16 +978,16 @@ function WebSpeechAPIDemo() { setListening(false); }; - reconizer.addEventListener("result", handleResult); - reconizer.addEventListener("error", handleError); - reconizer.addEventListener("end", handleEnd); + recognizer.addEventListener("result", handleResult); + recognizer.addEventListener("error", handleError); + recognizer.addEventListener("end", handleEnd); return () => { - reconizer.removeEventListener("result", handleResult); - reconizer.removeEventListener("error", handleError); - reconizer.removeEventListener("end", handleEnd); + recognizer.removeEventListener("result", handleResult); + recognizer.removeEventListener("error", handleError); + recognizer.removeEventListener("end", handleEnd); }; - }, [listening]); + }, [listening, recognizer]); const startListeningWeb = () => { setListening(true); @@ -1003,10 +999,10 @@ function WebSpeechAPIDemo() { console.log("Permissions not granted", result); return; } - reconizer.lang = "en-US"; - reconizer.continuous = true; - reconizer.interimResults = true; - reconizer.start(); + recognizer.lang = "en-US"; + recognizer.continuous = true; + recognizer.interimResults = true; + recognizer.start(); }); }; @@ -1023,12 +1019,12 @@ function WebSpeechAPIDemo() { reconizer.stop()} + onPress={() => recognizer.stop()} /> reconizer.abort()} + onPress={() => recognizer.abort()} /> )} diff --git a/package.json b/package.json index c77db92..c35dd2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "expo-speech-recognition", - "version": "0.2.16", + "version": "0.2.17", "description": "Speech Recognition for React Native Expo projects", "main": "build/index.js", "types": "build/index.d.ts", diff --git a/src/ExpoSpeechRecognitionModule.ts b/src/ExpoSpeechRecognitionModule.ts index 22e4421..10cc625 100644 --- a/src/ExpoSpeechRecognitionModule.ts +++ b/src/ExpoSpeechRecognitionModule.ts @@ -8,9 +8,31 @@ import type { ExpoSpeechRecognitionModuleType } from "./ExpoSpeechRecognitionMod // It loads the native module object from the JSI or falls back to // the bridge module (from NativeModulesProxy) if the remote debugger is on. -export const ExpoSpeechRecognitionModule = +const ExpoSpeechRecognitionNativeModule = requireNativeModule("ExpoSpeechRecognition"); +export const ExpoSpeechRecognitionModule = { + ...ExpoSpeechRecognitionNativeModule, + // Avoid any function bindings when calling the native module + stop: () => ExpoSpeechRecognitionNativeModule.stop(), + abort: () => ExpoSpeechRecognitionNativeModule.abort(), + requestPermissionsAsync: () => + ExpoSpeechRecognitionNativeModule.requestPermissionsAsync(), + getPermissionsAsync: () => + ExpoSpeechRecognitionNativeModule.getPermissionsAsync(), + getStateAsync: () => ExpoSpeechRecognitionNativeModule.getStateAsync(), + getAssistantService: () => + ExpoSpeechRecognitionNativeModule.getAssistantService(), + getDefaultRecognitionService: () => + ExpoSpeechRecognitionNativeModule.getDefaultRecognitionService(), + getSpeechRecognitionServices: () => + ExpoSpeechRecognitionNativeModule.getSpeechRecognitionServices(), + supportsOnDeviceRecognition: () => + ExpoSpeechRecognitionNativeModule.supportsOnDeviceRecognition(), + supportsRecording: () => + ExpoSpeechRecognitionNativeModule.supportsRecording(), +}; + export const ExpoSpeechRecognitionModuleEmitter = new EventEmitter( - ExpoSpeechRecognitionModule ?? NativeModulesProxy.ExpoSpeechRecognition, + ExpoSpeechRecognitionNativeModule ?? NativeModulesProxy.ExpoSpeechRecognition, );