gpt4 book ai didi

android - 如何在android中实现语音命令识别?

转载 作者:搜寻专家 更新时间:2023-11-01 08:45:34 27 4
gpt4 key购买 nike

您好,我想构建一个应用程序,让我的 Android 应用程序识别我的语音命令并执行特定任务。我搜索了很多但没有找到任何有效的解决方案。请问如何实现?

最佳答案

你可以看看this question如果你想要离线语音识别:

但还有另一种解决方案:

您可以使用 this app这是几年前由谷歌制作的。只需在您的设备中安装此应用,然后调用该应用即可:

private void startRecognizeSpeech() {

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

try {
startActivityForResult(intent, RESULT_SPEECH);

} catch (ActivityNotFoundException a) {
Toast.makeText(
getApplicationContext(),
"Oops! First you must download \"Voice Search\" App from Store",
Toast.LENGTH_SHORT).show();
}
}

然后在 onActivityResult() 中执行此操作:

@Override
// calls when voice recognition result received
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {
case RESULT_SPEECH: {
if (resultCode == RESULT_OK && null != data) {
// text is received form google
ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
//you can find your result in text Arraylist
}
break;
}
}
}

关于android - 如何在android中实现语音命令识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28719318/

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