使用RecognizerIntent.ACTION_RECOGNIZE_SPEECH的Google语音搜索不会执行操作

时间:2014-09-09 13:12:07

标签: android voice-recognition google-now recognizer-intent google-voice-search

我正在开发一个用户可以说出命令的应用程序,它将被执行。就像"语音搜索"来自Google的应用。我想使用与语音搜索相关的一组命令。

我的代码如下:

@Override
public void startVoiceRecognitionActivity() {
    // TODO Auto-generated method stub
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Command me");
    startActivityForResult(intent, REQUEST_CODE);
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
        case REQUEST_CODE: {
            ArrayList<String> matches = data
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            ApplicationDebug.printlog("got inside onactivityresult");
            String spokenText = matches.get(0);
            Toast.makeText(getApplicationContext(), spokenText,
                    Toast.LENGTH_LONG).show();
            // super.onActivityResult(requestCode, resultCode, data);
            break;
        }
    }
}

点击某个按钮我正在呼叫startVoiceRecognitionActivity()

正在检测语音,但此处没有发生此操作。我的意思是,如果我说&#34;打开计算器&#34;,它会正确显示文本,但不会打开计算器应用程序。

1 个答案:

答案 0 :(得分:0)

听起来你正在寻找这个:

RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE