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

时间:2013-03-28 14:44:00

标签: java android voice-recognition

我的应用使用Google的语音识别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。请建议更改或发布工作代码。提前谢谢。

1 个答案:

答案 0 :(得分:0)

只有在Jelly Bean中你才能达到你想要的效果,在onActivityResult你可以做到

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

对于JB以下的版本,只有在匹配或按下取消按钮时才会调用onActivityResult。