0

I have some code to convert speech to text but it runs only if the device has an internet Connection. I would like to see my code working offline and for that i already have gone through several codes from stackoverflow and other sources but still my code is not working in offline mode.

The device is Moto X Play. Enabled with offline speech recognition.

Here is the code that I have.

 private void promptSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    //intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,"en-US");
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,"en-US");
    intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,this.getPackageName());
    intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE,true);
    //intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    //intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}

Need help to understand it, I think I'm missing something.

Observation No other app is allowing for offline mode.

iSandeep
  • 597
  • 8
  • 24

1 Answers1

-2

I have used below code and it's going on in offline : follow its(http://www.androidhive.info/2014/07/android-speech-to-text-tutorial/)

 Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
        //intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US"));
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT,getString(R.string.speech_prompt));
        try {
            startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
        } catch (ActivityNotFoundException a) {
            Toast.makeText(getApplicationContext(),getString(R.string.speech_not_supported),Toast.LENGTH_SHORT).show();
        }
Suhail Mehta
  • 5,514
  • 2
  • 23
  • 37