voice icon indicating copy to clipboard operation
voice copied to clipboard

Error with Android 13 (Code 9, Code 12)

Open nl-danish opened this issue 2 years ago • 6 comments
trafficstars

Hello, I was implementing @react-native-voice/voice in my project, it seems to be working fine for iOS and Android devices that are below 12, However for Android 13 and so, i keep getting this errors while i'm trying to get it running.

1. onSpeechError:  {"error": {"code": "9", "message": "9/Insufficient permissions"}}
2. onSpeechError:  {"error": {"code": "12", "message": "12/Didn't understand, please try again."}}

The first error appear initially, then i go to the Google App and then set it's Microphone permission, and then the next error appears, every time i try to get it running.

Does anybody have an idea, how one may go about solving this? I've already tried solutions from their repo's issue that says to change the region, or to add some more engine parameters to the Voice.start function, or add some more queries to the AndroidManifest file. and few more stackoverflow solution, but they seem to be not working for me.

Please, take a look and let us know. Thank you

Here's some specification of our system and packages.

npx react-native info : System:
OS: macOS 13.3.1
CPU: (8) arm64 Apple M1
Memory: 113.25 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.16.0 - /opt/homebrew/opt/node@18/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 9.5.1 - /opt/homebrew/opt/node@18/bin/npm
Watchman: 2023.05.22.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.12.1 - /Users/appName/.rvm/gems/ruby-2.7.6/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2022.2 AI-222.4459.24.2221.9971841
Xcode: 14.1/14B47b - /usr/bin/xcodebuild
Languages:
Java: 11.0.19 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: ^17.0.2 => 17.0.2
react-native: ^0.66.5 => 0.66.5
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Real device? Or simulator? Real Device
What OS are you running?
For development: Mac.
For the bug: Android and Ios, both.

nl-danish avatar Oct 10 '23 08:10 nl-danish

@nl-danish, can you share how you are initialising Voice?

AngadSethi avatar Oct 15 '23 04:10 AngadSethi

Hi @AngadSethi,

Thanks for getting back. I ran it across more Android 13 devices, it seems to be working fine. However, this one device seems like an edge case to us.

This is how, we are initialising Voice. We are importing it, and have made a Custom Hook file to use Voice, to initialise, we are using an useEffect Hook.

useEffect(() => {
    Voice.onSpeechStart = onSpeechStart;
    Voice.onSpeechRecognized = onSpeechRecognized;
    Voice.onSpeechEnd = onSpeechEnd;
    Voice.onSpeechError = onSpeechError;
    Voice.onSpeechResults = onSpeechResults;
    Voice.onSpeechPartialResults = onSpeechPartialResults;
    Voice.onSpeechVolumeChanged = onSpeechVolumeChanged;

    return () => {
      Voice.destroy().then(Voice.removeAllListeners);
    };
  }, []);

As it seems to work on other Android 13 devices, are there any fixes for such edge cases? Please, let me know. Thanks, Danish

nl-danish avatar Oct 16 '23 06:10 nl-danish

@nl-danish, the error code 12 means that the locale you're passing to Voice.start is not supported by the device. This would probably imply that this language is supported by your other devices, but not by this one.

https://developer.android.com/reference/android/speech/SpeechRecognizer#ERROR_LANGUAGE_NOT_SUPPORTED

AngadSethi avatar Oct 16 '23 15:10 AngadSethi

Wow, this is nice.

Thank you so much, @AngadSethi

nl-danish avatar Oct 17 '23 06:10 nl-danish

You're welcome, @nl-danish!

AngadSethi avatar Oct 17 '23 07:10 AngadSethi

In android 13 i am still getting the error code 9 , any solution ?

somnathnath8482 avatar Mar 05 '24 13:03 somnathnath8482