2012-06-19 64 views

回答

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群众演员,看看是否有什么更适合您的需求。

+1

谢谢奥特拉。这是我需要的确切场景。我希望你也可以帮助我解决这个问题http://stackoverflow.com/questions/11105937/how-to-get-speechrecognizer-listner-response-in-js-function/ – littledev