jamsch / expo-speech-recognition

Speech Recognition for React Native Expo projects
MIT License
95 stars 9 forks source link

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

Open sgebr01 opened 3 weeks ago

sgebr01 commented 3 weeks 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 3 weeks 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.