SpeechRecognizer - 时间限制

时间:2012-06-19 19:05:04

标签: android speech-recognition voice-recognition

我正在使用SppechRecognizer语音识别器应用程序。它的工作正常。我的要求是我希望在1秒或2秒后停止语音收听。如何实现?

1 个答案:

答案 0 :(得分:8)

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可用的额外内容,看看是否有更适合您需求的内容。

相关问题