Android的语音识别命令命令、语音识别、Android

2023-09-05 04:11:22 作者:月亮杂货铺

目标

语音识别开始,语音命令是口头的和正确的行动已经完成。 (播放一些音乐开始一切应该发生的音乐播放器。)

Voice recognition starts, a voice command is spoken and the correct action is done. (Play Some Music starts the music player of whatever supposed to happen.)

现状

我有一个测试应用程序运行的开始Android的语音识别,成功地倾听并返回结果给我的活动。

I have a test application running which start the Android Voice Recognition, successfully listens and returns a result to my Activity.

片段启动语音识别:

 Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
 intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
 intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak your mind.");
 startActivityForResult(intent, REQUEST_CODE);

代码段的结果是:

Snippet for the result:

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
            ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            // matches hold the spoken words
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

什么是对这个问题的最好办法?

What would be the best approach for this problem?

推荐答案

最简单的方法是...

Easiest way is..

 if (matches.contains("close"))
        {
            finish();
        }