Android Voice Recognition Commands

天涯浪子 提交于 2019-12-31 04:19:07

问题


Goal

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.)

Current situation

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

Snippet to start voice recognition:

 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?


回答1:


Easiest way is..

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


来源:https://stackoverflow.com/questions/15122400/android-voice-recognition-commands

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!