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

Error: Can't find native module 'ExpoStt' #1

Closed
theobaronnat opened this issue May 11, 2023 · 12 comments
Closed

Error: Can't find native module 'ExpoStt' #1

theobaronnat opened this issue May 11, 2023 · 12 comments

Comments

@theobaronnat
Copy link

theobaronnat commented May 11, 2023

Hi, there is an error with your plugin:

image

Error come from ExpoSttModule.ts:
export default requireNativeModule("ExpoStt");

Here is part of my package.json:
{ "expo": "~48.0.15", "react-native": "0.71.7", "expo-stt": "^0.0.3", [...]}

@anhtuank7c
Copy link
Owner

Hi, this library does not support Expo Web and Expo Go.
It just support Bare React Native project or Expo but need to generate native code by execute this command npx expo prebuild --clean (which will generate ios and android with native code)

@theobaronnat
Copy link
Author

Okay, indeed I was running the command expo start --android instead of expo run:android. I no longer have that error, however, it doesn't seem to detect the voice.

image

@anhtuank7c
Copy link
Owner

anhtuank7c commented May 11, 2023

You must enable the host microphone from the emulator setting. It's disabled by default.

@theobaronnat
Copy link
Author

I have already enabled the microphone. Actually, it works for English language. I am French, so when I speak French, it doesn't work.
Is there a way to set the language?

@theobaronnat
Copy link
Author

I see that on file ExpoSttModule.kt:
val options = VoiceRecognizerContractOptions(Locale.getDefault())

I try, on App.tsx, to change the default locale like this:

setLocale(locale: string) { if (NativeModules.I18nManager) { NativeModules.I18nManager.localeIdentifier = locale; } },

console.log(LocaleConfig.getLocale()) LocaleConfig.setLocale('fr_FR'); console.log(LocaleConfig.getLocale())

The locale has changed, but the recognition language is always in English (United state).

@anhtuank7c
Copy link
Owner

Thank you so much for reporting this.
Actually we need some improvement such as: passing locale code while call ExpoStt.startSpeech(LOCALE_CODE) and also throw an exception in case locale is not available on device.
I think we could close this issue and create a new one for that one which stand for a clear purpose.

@anhtuank7c
Copy link
Owner

I've created a new issue for that at #2

@theobaronnat
Copy link
Author

I'm glad to hear that the speech recognition is working perfectly once your phone is set to your language. Thank you for your kind words and appreciation!
I'm looking forward to future improvements as well. If I come across any other areas for improvement, I'll let you know.

@anhtuank7c
Copy link
Owner

You're welcome.
I have a great experience cooperate with a French's dev in the past ^^!
Can we close this one?

@theobaronnat
Copy link
Author

It's great to hear that :) Of course, we can close this issue !

@ahadnawaz585
Copy link

ahadnawaz585 commented Jun 7, 2024

ERROR Error: Cannot find native module 'ExpoStt', js engine: hermes

import React, { useState, useEffect } from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import * as ExpoStt from 'expo-stt';

const SpeechToText = () => {
const [spokenText, setSpokenText] = useState('');
const [isRecognizing, setIsRecognizing] = useState(false);
const [error, setError] = useState('');

useEffect(() => {
const onSpeechStart = ExpoStt.addOnSpeechStartListener(() => {
setSpokenText('');
setError('');
setIsRecognizing(true);
});

const onSpeechResult = ExpoStt.addOnSpeechResultListener(({ value }) => {
  setSpokenText(value.join());
});

const onSpeechCancelled = ExpoStt.addOnSpeechCancelledListener(() => {
  setIsRecognizing(false);
});

const onSpeechError = ExpoStt.addOnSpeechErrorListener(({ cause }) => {
  setError(cause);
  setIsRecognizing(false);
});

const onSpeechEnd = ExpoStt.addOnSpeechEndListener(() => {
  setIsRecognizing(false);
});

return () => {
  onSpeechStart.remove();
  onSpeechResult.remove();
  onSpeechCancelled.remove();
  onSpeechError.remove();
  onSpeechEnd.remove();
};

}, []);

const startSpeechRecognition = async () => {
try {
await ExpoStt.startSpeech();
} catch (error) {
console.error('Speech recognition error:', error);
}
};

const stopSpeechRecognition = async () => {
try {
await ExpoStt.stopSpeech();
} catch (error) {
console.error('Speech recognition error:', error);
}
};

return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
Spoken Text: {spokenText}
{error ? Error: {error} : null}
<TouchableOpacity
onPress={isRecognizing ? stopSpeechRecognition : startSpeechRecognition}
style={{
marginTop: 20,
padding: 10,
backgroundColor: isRecognizing ? 'red' : 'green',
borderRadius: 5,
}}>
<Text style={{ color: 'white' }}>
{isRecognizing ? 'Stop Recognition' : 'Start Recognition'}



);
};

export default SpeechToText;

"plugins": [
  "expo-font",
    [
      "expo-stt",
      {
        "microphonePermission": "Allow $(PRODUCT_NAME) to access your microphone",
        "speechRecognitionPermission": "Allow $(PRODUCT_NAME) to access your speech recognition"
      }
  ]
],

image

image

WhatsApp Image 2024-06-07 at 12 53 43_9af90f52

tell me asap !
where i am doing wrong coz it's not wokring

@anhtuank7c
Copy link
Owner

ahadnawaz585
This module does not support Expo Go or the web. Please generate native directory if you're using Expo: npx expo prebuild --clean or use it with bare React Native project.

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

3 participants