Android的语音识别命令 [英] Android Voice Recognition Commands

查看:166
本文介绍了Android的语音识别命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标

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

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

这篇关于Android的语音识别命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆