jamsch / expo-speech-recognition

Speech Recognition for React Native Expo projects
MIT License
128 stars 11 forks source link

Issue with start function when trying to use library on bare react native app #38

Open sgebr01 opened 1 month ago

sgebr01 commented 1 month ago

I'm having an issue when I try to use the library and call the start function on a bare react native app that doesn't use expo (even though I do use expo modules). Other functions (like stop), do work. When I try to call it, I get an error _$$_REQUIRE(_dependencyMap[8],"(...)xpoSpeechRecognitionModule.start is not a function (it is undefined)

And when I log ExpoSpeechRecognitionModule, this is what I get {"abort": [Function abort], "getAssistantService": [Function getAssistantService], "getDefaultRecognitionService": [Function getDefaultRecognitionService], "getPermissionsAsync": [Function getPermissionsAsync], "getSpeechRecognitionServices": [Function getSpeechRecognitionServices], "getStateAsync": [Function getStateAsync], "isRecognitionAvailable": [Function isRecognitionAvailable], "requestPermissionsAsync": [Function requestPermissionsAsync], "stop": [Function stop], "supportsOnDeviceRecognition": [Function supportsOnDeviceRecognition], "supportsRecording": [Function supportsRecording]} and as we would expect the start function is missing for some reason. I have made sure to request permissions and even the example you gave does not work.

jamsch commented 1 month ago

Hey @sgebr01, here's a few things you may want to check, and let me know:

import { requireNativeModule } from "expo-modules-core";

const ExpoSpeechRecognitionNativeModule = requireNativeModule("ExpoSpeechRecognition");

console.log(ExpoSpeechRecognitionNativeModule);
console.log(ExpoSpeechRecognitionNativeModule.start);

Under the hood, I'm aliasing the functions on the native module here, which is why you only see a subset of them https://github.com/jamsch/expo-speech-recognition/blob/42f52a875602ee01c9f9e80bd6329359a9c081f8/src/ExpoSpeechRecognitionModule.ts#L11-L36

It's possible that older versions of React Native/Expo Modules loaded the module as a proxy object which would make this not working too.

sgebr01 commented 1 week ago

Sorry for the delay: my version of expo-modules-core is 1.12.24. I have rebuilt my app several times afterwards. I'm on react-native 0.75.2.

Here's what I get when I try to log that.

Module {"__expo_module_name__": "ExpoSpeechRecognition", "abort": [Function abort], "addListener": [Function addListener], "androidTriggerOfflineModelDownload": [Function androidTriggerOfflineModelDownload], "emit": [Function emit], "getAssistantService": [Function getAssistantService], "getAudioSessionCategoryAndOptionsIOS": [Function getAudioSessionCategoryAndOptionsIOS], "getDefaultRecognitionService": [Function getDefaultRecognitionService], "getPermissionsAsync": [Function getPermissionsAsync], "getSpeechRecognitionServices": [Function getSpeechRecognitionServices], "getStateAsync": [Function getStateAsync], "getSupportedLocales": [Function getSupportedLocales], "isRecognitionAvailable": [Function isRecognitionAvailable], "listenerCount": [Function listenerCount], "removeAllListeners": [Function removeAllListeners], "removeListener": [Function removeListener], "removeSubscription": [Function removeSubscription], "requestPermissionsAsync": [Function requestPermissionsAsync], "setAudioSessionActiveIOS": [Function setAudioSessionActiveIOS], "setCategoryIOS": [Function setCategoryIOS], "start": [Function start], "stop": [Function stop], "supportsOnDeviceRecognition": [Function supportsOnDeviceRecognition], "supportsRecording": [Function supportsRecording]}

Start Function

[Function start]
jamsch commented 1 week ago

Hey @sgebr01, it looks like expo-modules-core@v2.0.0 added support for React Native 0.75 so you'll likely need to upgrade. Version 1.0.0 of this package uses expo-modules-core v2

sgebr01 commented 1 week ago

Sounds good, I will try that out and let you know.