【发布时间】:2012-06-20 03:28:53
【问题描述】:
我将SppechRecognizer 用于语音识别应用程序。它工作正常。我的要求是我想在 1 秒或 2 秒后停止收听语音。如何实现?
【问题讨论】:
标签: android speech-recognition voice-recognition
我将SppechRecognizer 用于语音识别应用程序。它工作正常。我的要求是我想在 1 秒或 2 秒后停止收听语音。如何实现?
【问题讨论】:
标签: android speech-recognition voice-recognition
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 的附加功能,看看是否有更适合您的需求。
【讨论】: