【发布时间】:2016-08-30 20:02:52
【问题描述】:
使用此代码:
private void promptSpeechInput() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
getString(R.string.speech_prompt));
try {
startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
} catch (ActivityNotFoundException a) {
Toast.makeText(getApplicationContext(),
getString(R.string.speech_not_supported),
Toast.LENGTH_SHORT).show();
}
}
通过不同的方式(按钮事件、手势、生命周期),我可以调用此方法来打开语音输入提示,就像我在谷歌搜索字段中单击麦克风图标一样。 好的,很好。
但是现在,我需要使用命令语音调用此方法。就像现在在 google 中一样,我们说“Ok Google”,然后出现语音输入提示。我想在我的应用程序中执行此操作。例如,我在主要活动中,我说“听我说”并调用方法 promptSpeechInput。
我该怎么做?
感谢您的帮助。
【问题讨论】:
标签: android voice-recognition google-now