我正在做仪表板应用程序,其中有很多屏幕。当用户根据语音指令告诉我需要打开活动的时候。我不知道从哪里开始,我已经完成了所有的屏幕,我想实现语音搜索。我的应用程序屏幕是前进,离开,招聘,权限,通知等示例:当用户说‘前进’时,它应该打开前进屏幕。请帮帮我。
发布于 2013-01-21 14:01:13
1)启动语音识别意图
2)在onActivityResult()中处理返回的数据,以决定启动哪个活动
1.启动语音识别意图
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Choose Activity");
startActivityForResult(intent, REQUEST_SPEECH);2.处理返回数据
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == REQUEST_SPEECH){
if (resultCode == RESULT_OK){
ArrayList<String> matches = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
if (matches.size() == 0) {
// didn't hear anything
} else {
String mostLikelyThingHeard = matches.get(0);
// toUpperCase() used to make string comparison equal
if(mostLikelyThingHeard.toUpperCase().equals("ADVANCES")){
startActivity(new Intent(this, Advances.class));
} else if() {
}
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}https://stackoverflow.com/questions/14432836
复制相似问题