语音识别器 - 时间限制

3

我正在使用SpeechRecognizer进行语音识别应用程序,它工作得很好。我的需求是在1秒或2秒后停止语音识别功能。如何实现?

1个回答

9

1或2秒似乎不是很多时间,但如果您想设置时间限制,可能需要进行线程处理。 Android具有一些默认扩展来设置语音输入的最小长度和用户停止说话后的最大时间,但没有设置语音输入时间的最大长度。

您最好使用类似于 CountDownTimer 的定时器进行线程处理:

 yourSpeechListener.startListening(yourRecognizerIntent);
 new CountDownTimer(2000, 1000) {

     public void onTick(long millisUntilFinished) {
         //do nothing, just let it tick
     }

     public void onFinish() {
         yourSpeechListener.stopListening();
     }
  }.start();

我还建议您查看RecognizerIntent提供的额外功能,看看是否有更适合您需求的内容。

1
谢谢Otra。这正是我需要的情况。我希望您也能帮我解决这个问题:http://stackoverflow.com/questions/11105937/how-to-get-speechrecognizer-listner-response-in-js-function/ - littledev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接