gpt4 book ai didi

android - 如何根据语音命令打开Activity

转载 作者:太空狗 更新时间:2023-10-29 12:49:08 26 4
gpt4 key购买 nike

我正在做有很多屏幕的仪表板应用程序。当用户告诉基于我需要打开 Activity 的语音命令时。我不知道从哪里开始 我已经完成了所有屏幕,我想实现语音搜索。我的应用程序屏幕是 Advances、Leaves、Recruitment、Permissions、Notifications 等示例:当用户说“预付款”时,它应该打开预付款屏幕。请帮助我。

最佳答案

1) 启动语音识别 Intent

2) 处理onActivityResult()中的返回数据,决定启动哪个activity

<强>1。启动语音识别 Intent

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

关于android - 如何根据语音命令打开Activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14432836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com