Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sgebr01 opened this issue Oct 5, 2024 · 4 comments

Comments

@sgebr01
Copy link

sgebr01 commented Oct 5, 2024

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
Copy link
Owner

jamsch commented Oct 5, 2024

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

  • Whether you've re-built your app after installing. I don't have any instructions yet for bare CLI, but there'll need to be changes to your Info.plist and AndroidManifest.xml in regards to permissions and speech service package discoverability.
  • The version of your expo-modules-core
  • Also just console logging the native module:
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

const ExpoSpeechRecognitionNativeModule =
requireNativeModule<ExpoSpeechRecognitionModuleType>("ExpoSpeechRecognition");
export const ExpoSpeechRecognitionModule: ExpoSpeechRecognitionModuleType = {
...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(),
isRecognitionAvailable: () =>
ExpoSpeechRecognitionNativeModule.isRecognitionAvailable(),
};

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
Copy link
Author

sgebr01 commented Nov 17, 2024

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
Copy link
Owner

jamsch commented Nov 17, 2024

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
Copy link
Author

sgebr01 commented Nov 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants