4

This is how i start my RecogniseListener intent:

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);   
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

intent.putExtra("android.speech.extra.DICTATION_MODE", true);               
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,this.getPackageName());
intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,1);
sr.startListening(intent);

However, i get a strange behavior. It works on some phones (Samsung galaxy S5, in this case), but i get the following error on Lenovo K50-T5:

E/SpeechRecognizer: no selected voice recognition service

This is my AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="lips.deafcommunication.deaflips">

<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppThemeNoBar">
    <activity android:name=".MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".ChatInProgressActivity" android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan"
                android:configChanges="keyboardHidden|orientation|screenSize"
        ></activity>
</application>
</manifest>
1
  • i getting same error because if you go to mobile device setting > Language and input > voice input > you find two option non one selected by default
    – Hamza
    Commented Sep 2, 2017 at 14:13

4 Answers 4

7

In my case this warning case by user device if he/she not selected speech recognizer service by default here is photo of settings witch casing this problem, you see in photo no service selected by default,

enter image description here

i fix this by explicitly adding GoogleRecognitionService to my SpeechRecognizer,At the end my code look like this one

 this.speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getActivity(), ComponentName.unflattenFromString("com.google.android.googlequicksearchbox/com.google.android.voicesearch.serviceapi.GoogleRecognitionService"));

So your code look like you using default speech intent, make your own custom recognitionlistener here is link to How can I use speech recognition without the annoying dialog in android phones

Note: Make sure you have install Google app

5
  • This is a fundamentally wrong solution: "googlequicksearchbox" might not be installed, or might not be installed in the future, or might not be what the user wants to use. The correct solution is to inform the user that no recognizer is installed/selected and then open a dialog helping the user with the installation/selection.
    – Kaarel
    Commented Feb 3, 2018 at 23:17
  • inform to user that no recognizer is part of UX, i am only showing what case the problem i suppose programmer smart enough to inform to user that no recognizer check before calling to google speech
    – Hamza
    Commented Feb 4, 2018 at 9:21
  • 1
    So Far Hamza's solution of providing a ComponentName in createSpeechRecognizer is the ONLY thing that has worked for me. I can't for the life of me find where or how to "install" a recognizer on any Android Device.
    – AlanKley
    Commented Apr 27, 2018 at 22:17
  • 1
    Make sure you have install Google app in your phone most of phone have by defult some time its disable by user play.google.com/store/apps/…
    – Hamza
    Commented May 23, 2018 at 13:37
  • Thanks, that worked. Can also put this check to make this fool-proof stackoverflow.com/a/56319307/4411645
    – AA_PV
    Commented May 27, 2019 at 3:26
5

That means either the user doesn't have a speech recognizer installed at all, or doesn't have one configured to run. There's nothing you can do to fix that, the user has to install one.

5

The error indicates there are no speech recognizer services available. You should test for this condition before calling SpeechRecognizer.createSpeechRecognizer.

import android.speech;

if(SpeechRecognizer.isRecognitionAvailable(this)) {
    SpeechRecognizer sr = SpeechRecognizer.createSpeechRecognizer(this);
} else {
    // SOME SORT OF ERROR
}
0

To make Hamza's solution fool-proof, you can add the following checks, to pre-empt the different errors in the logs on startVoiceRecognition()

private static final String GOOGLE_RECOGNITION_SERVICE_NAME = "com.google.android.googlequicksearchbox/com.google.android.voicesearch.serviceapi.GoogleRecognitionService"

public static boolean isSpeechRecognizerAvailable() {
    if (sIsSpeechRecognizerAvailable == null) {
        boolean isRecognitionAvailable = context != null && context.getPackageManager() != null
                && SpeechRecognizer.isRecognitionAvailable(context);
        if (isRecognitionAvailable) {
            ServiceConnection connection = new ServiceConnection() {
                @Override
                public void onServiceConnected(ComponentName name, IBinder service) {

                }

                @Override
                public void onServiceDisconnected(ComponentName name) {

                }
            };
            Intent serviceIntent = new Intent(RecognitionService.SERVICE_INTERFACE);
            ComponentName recognizerServiceComponent = ComponentName.unflattenFromString(GOOGLE_RECOGNITION_SERVICE_NAME);
            if (recognizerServiceComponent == null) {
                return false;
            }

            serviceIntent.setComponent(recognizerServiceComponent);
            boolean isServiceAvailableToBind = context.bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE);
            if (isServiceAvailableToBind) {
                context.unbindService(connection);
            }
            sIsSpeechRecognizerAvailable = isServiceAvailableToBind;
        } else {
            sIsSpeechRecognizerAvailable = false;
        }
    }
    return sIsSpeechRecognizerAvailable;
}

and then use the same component name to initialise the speech recogniser

this.speechRecognizer = SpeechRecognizer.createSpeechRecognizer(context, ComponentName.unflattenFromString(GOOGLE_RECOGNITION_SERVICE_NAME));
1
  • 1
    what is "GOOGLE_RECOGNITION_SERVICE_NAME"? Commented Oct 8, 2019 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.