Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
835 views
in Technique[技术] by (71.8m points)

android - SpeechRecognizer - time limit

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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();

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...