SpeechRecognizerListener giving Bundle[EMPTY_PARCEL] in onResults(Bundle results) majority devices which have android 11
Asked Answered
I

3

2

I am Using

speech = SpeechRecognizer.createSpeechRecognizer(getReactApplicationContext().getApplicationContext());
            speech.setRecognitionListener(VoiceAppModule.this);
            recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS, 100000000);
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.languageacademy");
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 10000);
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, 10000);

The Above code for Speech recognition.

@Override public void onResults(Bundle results) {

in about On Result the result is giving Bundle[EMPTY_PARCEL] in Result.

ArrayList matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);

I tried in many of the Devices it is mainly giving problem in MI phones having android 11 and also some samsung phones.

Intuit answered 14/4, 2022 at 10:2 Comment(0)
S
2

Same problem here, this bug started to occur like few days ago.

I think the reason of this bug is the new version of "Google" app (https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox), as SpeechRecognizer uses this app to recognize voice.

If you click uinstall "Google" app, it will roll back to older version and onResult callback will work fine.

Solution that fixed my problem was removing: EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS extras

Note that it is extremely rare you'd want to specify this value in an intent. Generally, it should be specified only when it is also used as the value for EXTRA_SEGMENTED_SESSION to enable segmented session mode. Note also that certain values may cause undesired or unexpected results - use judiciously!

https://developer.android.com/reference/android/speech/RecognizerIntent#EXTRA_SEGMENTED_SESSION

Stane answered 15/4, 2022 at 11:19 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Cidevant
T
1

I confirm the answer gave by Seba, only in my case I have to remove also

RecognizerIntent.EXTRA_MAX_RESULTS RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS RecognizerIntent.EXTRA_SPEECH_INPUT_MINIMUM_LENGTH_MILLIS RecognizerIntent.EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS

and affected also Huawei and Samsung devices with Android 9, so it seems the issues's propagating day by day.

Theoretician answered 5/5, 2022 at 9:28 Comment(0)
H
1

I was also facing the same issue. After removing the below intent it started working.

putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 3000)

Previous intent :

 recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
      putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en")
      putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, packageName)
      putExtra(
        RecognizerIntent.EXTRA_LANGUAGE_MODEL,
        RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH
      )
      putExtra(RecognizerIntent.EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, 3000)
      putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1)
    }

Modified Intent:

recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
  putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en")
  putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, packageName)
  putExtra(
    RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH
  )
  putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1)
}
Hell answered 31/5, 2022 at 6:47 Comment(1)
but I need to use EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS , to wait 3-4 sec after user complete to talkMunsey

© 2022 - 2024 — McMap. All rights reserved.