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: Failed to retrieve supported locales with error: 14] when calling ExpoSpeechRecognitionModule.getSupportedLocales #60

Open
NamHyeongKeol opened this issue Nov 21, 2024 · 1 comment

Comments

@NamHyeongKeol
Copy link

This error occurs quite frequently when using ExpoSpeechRecognitionModule.getSupportedLocales. However, it doesn’t always happen—when running the feature that calls this function multiple times, it works sometimes and fails other times. Usually, the first time the feature is executed after launching the app, the error almost always occurs. After that, it may or may not happen.

Interestingly, after experimenting further, there were cases where the error message ([Error: Failed to retrieve supported locales with error: 14]) didn’t appear at all, and the function simply didn’t run. I am using the fetchSupportedLocalesForAndroid function defined as below, but in this situation, not even a console.log is printed, nor does any error message show up. There was only one instance where this issue occurred, but restarting the phone resolved it.

Is there any way to ensure this function runs reliably?

export const fetchSupportedLocalesForAndroid = async () => {
  try {
    const supportedLocalesTTS = await ExpoSpeechRecognitionModule.getSupportedLocales({
      androidRecognitionServicePackage: "com.google.android.tts"
    });
    console.log("tts Supported locales:", supportedLocalesTTS.locales.join(", "));
    console.log("tts On-device locales:", supportedLocalesTTS.installedLocales.join(", "));

    const supportedLocalesAS = await ExpoSpeechRecognitionModule.getSupportedLocales({
      androidRecognitionServicePackage: "com.google.android.as"
    });
    console.log("as Supported locales:", supportedLocalesAS.locales.join(", "));
    console.log("as On-device locales:", supportedLocalesAS.installedLocales.join(", "));

    return { supportedLocalesTTS, supportedLocalesAS };
  } catch (error) {
    console.log('Error fetching supported locales:', error);
    return { supportedLocalesTTS: { locales: [], installedLocales: [] }, supportedLocalesAS: { locales: [], installedLocales: [] } };
  }
};
@jamsch
Copy link
Owner

jamsch commented Nov 21, 2024

I ran in to this error as well when developing the feature to be able to specify the android service package. The error 14 corresponds to SpeechRecognizer.ERROR_CANNOT_CHECK_SUPPORT

What happens is that I'm calling the SpeechRecognizer.checkRecognitionSupport() function with the callbacks: onSupportResult() and onError(). The issue is that with some of the speech services, both the onError() and onSupportResult() fire but I can't actually figure out why that's the case.

So I ended up adding a 50ms timeout on the onError() invocation which worked okay on my device, but that might just need to be tweaked.

override fun onError(error: Int) {
Log.e("ExpoSpeechService", "getSupportedLocales.onError() called with error code: $error")
// This is a workaround for when both the onSupportResult and onError callbacks are called
// This occurs when providing some packages such as com.google.android.tts
// com.samsung.android.bixby.agent usually errors though
Handler(appContext.mainLooper).postDelayed({
if (didResolve) {
return@postDelayed
}
promise.reject(
"error_$error",
"Failed to retrieve supported locales with error: $error",
Throwable(),
)
}, 50)
recognizer.destroy()
}

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