0

I use RecognizerIntent that works pretty well (see the below function). What I want is to run in offline mode. If RecognizerIntent is not a good solution what is the alternative? Also if it is another solution I will want to set the language...Thanks

public void speak(View view) {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        // Specify the calling package to identify your application
        intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass()
                .getPackage().getName());

        // Display an hint to the user about what he should say.
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, metTextHint.getText()
                .toString());

        // Given an hint to the recognizer about what the user is going to say
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

        // If number of Matches is not selected then return show toast message
        if (msTextMatches.getSelectedItemPosition() == AdapterView.INVALID_POSITION) {
            Toast.makeText(this, "Please select No. of Matches from spinner",
                    Toast.LENGTH_SHORT).show();
            return;
        }

        int noOfMatches = Integer.parseInt(msTextMatches.getSelectedItem()
                .toString());
        // Specify how many results you want to receive. The results will be
        // sorted where the first result is the one with higher confidence.

        intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, noOfMatches);

        startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
    }
Lucian Novac
  • 1,255
  • 12
  • 18
  • You can't specifically request offline mode. See this answer http://stackoverflow.com/a/17674655/1256219 – brandall Jul 14 '14 at 09:34

2 Answers2

1

You need to define language english US.-

recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");

Now put phone on "Airplane Mode" and test.

Note- It will work offline only in API-16+

Arnav M.
  • 2,590
  • 1
  • 27
  • 44
0
intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);
Corxit Sun
  • 618
  • 6
  • 8
  • 2
    While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context. – Dima Kozhevin Dec 29 '18 at 13:01