noobEinstien
noobEinstien

Reputation: 3283

Offline SpeechRecognizer on Android is not working

I am working with SpeechRecognizer. The problem was if there is no active internet connection SpeechRecognizer will throw error SpeechRecognizer.ERROR_NETWORK or SpeechRecognizer.ERROR_SERVER.

This is my RecognizerIntent

    final Intent recognizerIntent;
    recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);

    recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);

And I put recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);

But no luck. again it will throw the same error.

And I got these 2 errors frequently.

  1. SpeechRecognizer.ERROR_RECOGNIZER_BUSY
  2. SpeechRecognizer.ERROR_NO_MATCH

Please help me.

Upvotes: 4

Views: 2448

Answers (1)

Artem_Iens
Artem_Iens

Reputation: 312

First of all, you need to make sure if you have offline package of language you put to EXTRA_LANGUAGE_PREFERENCE installed on the device.

To enable Offline Speech input in supported devices, follow below steps:

  • Go to Settings
  • Click on “Language and input”
  • On-screen keyboard
  • Select Google voice typing
  • Select Offline speech recognition
  • Install desired language

If it still does not work offline, try to change your EXTRA_LANGUAGE_PREFERENCE value to something more specific, "en-US" for example (That did the trick for me)

And also, if you want to tell SpeechRecognizer wich language it should recognize, I guess you should use EXTRA_LANGUAGE parameter instead of EXTRA_LANGUAGE_PREFERENCE

Hope it will help

Upvotes: 3

Related Questions