3

我正在将SppechRecognizer用于语音识别器应用程序。它工作正常。我的要求是我想在 1 秒或 2 秒后停止语音收听。如何做到这一点?

4

1 回答 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的附加功能,看看是否有更适合您需求的东西。

于 2012-06-19T19:28:53.637 回答