Android 脱机模式下的识别器意图

Android 脱机模式下的识别器意图,android,voice-recognition,Android,Voice Recognition,我使用的ReconfizerIntent工作得很好(请参见下面的函数)。我想要的是在脱机模式下运行。如果RecogenerIntent不是一个好的解决方案,那么替代方案是什么?此外,如果这是另一个解决方案,我会想设置语言…谢谢 public void speak(View view) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); // Specify the call

我使用的ReconfizerIntent工作得很好(请参见下面的函数)。我想要的是在脱机模式下运行。如果RecogenerIntent不是一个好的解决方案,那么替代方案是什么?此外,如果这是另一个解决方案,我会想设置语言…谢谢

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);
    }

你需要给我们定义英语语言-

recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
现在将手机置于“飞行模式”并进行测试


注意-它只能在API-16+下脱机工作。

您不能特别请求脱机模式。查看此答案虽然此代码可能会回答问题,但最好解释如何解决问题,并提供代码作为示例或参考。只有代码的答案可能会令人困惑,并且缺乏上下文。
intent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);