您好,我想构建一个应用程序,让我的 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/