Android Speech Recognition Insufficient Resolution (Error Code 9)

I am trying to implement speech recognition without a standard dialogue (it works fine with dialogue).

I get error code 9 as soon as I try to start listening.

My device is LG G Stylo (runs on Android 6.0).

manifest:

<manifest package="example.com.myapplication" xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <application ..... 

(also tried adding INTERNET permission, although this is not necessary, since autonomous recognition should work)

build.gradle:

 compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "example.com.appname" minSdkVersion 19 targetSdkVersion 23 versionCode 1 versionName "1.0" } 

Speech Recognition Code:

 private SpeechRecognizer speechRecognizer; protected void onCreate(Bundle savedInstanceState) { speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this); speechRecognizer.setRecognitionListener(new speech_listener()); Intent intent = new intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getApplication().getPackageName()); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.ENGLISH); speechRecognizer.startListening(intent); 

Listener (inner) class:

 class speech_listener implements RecognitionListener { public void onReadyForSpeech(Bundle params){} public void onBeginningOfSpeech(){} public void onRmsChanged(float rmsdB){} public void onBufferReceived(byte[] buffer){} public void onEndOfSpeech(){} public void onError(int error){ Log.d("Speech", "error: " + error); } public void onResults(Bundle results) { ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); String answer = (String)data.get(0); processAnswer(answer); } public void onPartialResults(Bundle partialResults){} public void onEvent(int eventType, Bundle params){} } 

Any insight would be appreciated.

+6
source share
2 answers

On Android 6, this permission is one of the dangerous, which means that you need to ask the user to confirm it (actually acquire). this and this for more details.

+10
source

Adding to Sam answer : when you are developing an application on Android 6, you may not need to approve the β€œdangerous” permission to record sound (microphone), so you need to manually open the application in the settings and provide permission.

Manual Screenshot

+13
source

All Articles