2012-06-19 63 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