如何在没有对话框提示的情况下自动重试语音识别



我的应用程序使用谷歌的语音识别API。我希望这是一种免提体验,但当它无法识别语音时,它会提示用户点击对话框中的按钮再试一次。如何避免这种情况并自动重试。我知道我应该检查resultCode。这是我尝试的:

if(resultCode == RecognizerIntent.RESULT_NO_MATCH){
/* I wasnt' able to retry voice recognition, so instead to check
if I'm able to actually check if resultCode == RecognizerIntent.RESULT_NO_MATCH
I tried this */
TextView.setText("No match");
}

但这不起作用。唯一有效的是RESULT_CANCELED和RESULT_OK。请建议更改或张贴工作代码。

只有在Jelly Bean中你才能实现你想要的,在onActivityResult中你可以做一个

if(resultCode == RecognizerIntent.RESULT_OK)  
// handle result
else
//finish Google voice recognition and start again.

对于JB以下的版本,onActivityResult仅在存在匹配或按下取消按钮时调用。

最新更新