SpeechRecognizer-时间限制 [英] SpeechRecognizer - time limit
问题描述
我正在将 SppechRecognizer 用于语音识别器应用程序.它的工作正常.我的要求是我想在1秒或2秒后停止收听声音.如何实现?
I am using SppechRecognizer for voice recognizer application. Its working fine. My requirement is i want to stop the voice listening after 1 sec or 2 sec. How to achieve that?
推荐答案
1或2秒似乎没有很多时间,但如果要设置时间限制,则可能需要穿线.Android有一些默认的附加功能,可以设置语音输入的最小长度和用户停止讲话后的最大长度,但没有其他功能可以设置语音输入的最大时间长度.
1 or 2 seconds doesn't seem to be a lot of time but if you want to set a time limit, you'd probably have to thread it. Android has some default extras to set the minimum length of speech input and maximum amount after a user has stopped speaking, but none to set the maximum length of time for speech input.
您最好的选择是安排某种计时器,例如 CountDownTimer :
Your best bet would be to thread some sort of timer, something like a 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 可用的其他功能.看看是否还有其他更适合您的需求.
I would also encourage you to look at the extras available for the RecognizerIntent to see if there's anything more suitable to your needs.
这篇关于SpeechRecognizer-时间限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!