Android SpeechRecognizer when do I get ERROR_CLIENT when starting the voice recognizer?
Asked Answered
S

4

9

I am not sure about some documentation related stuff.

To sum up what I did and what I want to to: I managed to introduce voice recognition feature into an Android application that is running on Android 4.2 on a tablet, and it works ok. Now I want to port my application on Google Glass but unfortunately I get the following error when I try to start the speech recognizer: error 5 -> ERROR_CLIENT(Other client side errors). The message guides me to find other errors that not related to SpeechRecognizer object, but I don't get any in my logs, not even warnings. So my question would be: When exactly do I get ERROR_CLIENT? and what should look the errors that block the recognizer to start?

Thank you! :)

Shrunk answered 28/7, 2014 at 12:46 Comment(2)
You probably forgot Audio permission in your manifest.Bartie
No, not at all. When I don't have enough permissions I receive another code, and that is 9 not 5.Shrunk
S
7

So after a bit of pain I manage to solve my problem regarding my glass application.

First of all I found that SpeechRecognizer only works when my glasses are connected to the internet! Even so I still received from times to times ERROR 5. That was because I have a bad connectivity to the internet and from times to times my glass just disconnected from the internet without any notifications! I think this is an issue that must be solved for the next level of glasses. It just cannot disconnect from the internet without notifying you.

So one of the causes for ERROR_CLIENT(5) on Google Glass is: not having internet connection

Shrunk answered 29/7, 2014 at 8:39 Comment(1)
"because I have a bad connectivity to the internet" could explain ERROR_CLIENT(5) on Android smartphones, too?Shoup
E
10

I found this link that is the source code for producing the errors.

SpeechRecognizer source

There are 7 places where a search found "ERROR_CLIENT"

Here's the log statements right before the ERROR_CLIENT is sent to onError

  • Log.e(TAG, "no selected voice recognition service");
  • Log.e(TAG, "bind to recognition service failed");
  • Log.e(TAG, "startListening() failed", e);
  • Log.e(TAG, "stopListening() failed", e);
  • Log.e(TAG, "cancel() failed", e);
  • Log.e(TAG, "not connected to the recognition service");

Of course you can find more info at the above link, but this should give you the general reasons why you'd get ERROR_CLIENT

Excellent answered 25/1, 2017 at 22:46 Comment(1)
Any idea why my Android Studio (2021.3) does not show those Log.e(...) messages in the Debug console?Shoup
S
7

So after a bit of pain I manage to solve my problem regarding my glass application.

First of all I found that SpeechRecognizer only works when my glasses are connected to the internet! Even so I still received from times to times ERROR 5. That was because I have a bad connectivity to the internet and from times to times my glass just disconnected from the internet without any notifications! I think this is an issue that must be solved for the next level of glasses. It just cannot disconnect from the internet without notifying you.

So one of the causes for ERROR_CLIENT(5) on Google Glass is: not having internet connection

Shrunk answered 29/7, 2014 at 8:39 Comment(1)
"because I have a bad connectivity to the internet" could explain ERROR_CLIENT(5) on Android smartphones, too?Shoup
E
1

The error happens also if the Google search application has no permissions to the microphone. In that case, the phone speech recognition service will be disabled and the ERROR_CLIENT error will be triggered for all apps (the above case was verified on a Samsung phone running Android 11)

Emilia answered 19/4, 2021 at 13:45 Comment(1)
I get this ERROR_CLIENT(5) despite (Google)[play.google.com/store/apps/… app having the required permissions to the microphone. Verified. This happens sporadically, so I believe @IspasClaudiu's is the correct explanation in my case.Shoup
F
1

I got this error because I was using an object variable inside the main loop:

class SpeechRecognition implements RecognitionListener {
    private SpeechRecognizer recognizer;

    public void transcribe (Activity activity) {
        new Handler(Looper.getMainLooper()).post(() -> {
            this.speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this.activity);
            this.speechRecognizer.setRecognitionListener(this.listener);

            Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)

            this.speechRecognizer.startListening(intent);
        }
    }

    [...]
 }

Solution:

class SpeechRecognitionRunnable implements Runnable {
    private volatile SpeechRecognizer speechRecognizer;
    private RecognitionListener listener;
    private Activity activity;

    public SpeechRecognitionRunnable (RecognitionListener listener, Activity activity) {
        this.listener = listener;
        this.activity = activity;
    }

    @Override
    public void run() {
        this.speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this.activity);
        this.speechRecognizer.setRecognitionListener(this.listener);

        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

        this.speechRecognizer.startListening(intent);
    }

    public SpeechRecognizer getSpeechRecognizer() {
        return this.speechRecognizer;
    }
}

class SpeechRecognition implements RecognitionListener {
    private SpeechRecognizer recognizer;

    public void transcribe (Activity activity) {
        new Handler(Looper.getMainLooper()).post(new SpeechRecognitionRunnable(this, activity)
    }

    [...]
 }
Fernandez answered 17/1, 2022 at 13:34 Comment(3)
Nice! Could you explain a bit more about the root cause and your solution? By "object variable" are you referring to Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH) ?Shoup
I think it was due to the speechRecognizer variable. Unfortunately, I don't really know why this fixed it. I was just happy that it did :)Fernandez
Thank you. I am struggling now with the same issue. Using the stack trace approach, I can forensically try to find out what caused it. It would be nice, though, to get that information during runtime, so that it can be passed to the end-user (after proper translation, of course).Shoup

© 2022 - 2024 — McMap. All rights reserved.