Leap Bun
Leap Bun

Reputation: 2295

How to pause and resume SpeechRecognizer in Android?

I am using SpeechRecognizer class.

Here is my code:

SpeechRecognizer     speechRecognizer;
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getBaseContext());
MyRecognitionListener speechListner=new MyRecognitionListener();
speechRecognizer.setRecognitionListener(speechListner);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getApplication().getPackageName());
speechRecognizer.startListening(intent);

The problem is that I could not pause and resume it. I already tried:

speechRecognizer.cancel();
speechRecognizer.stopListening();

But it still listen.

Upvotes: 1

Views: 2547

Answers (1)

Erol
Erol

Reputation: 6526

You cannot call stopListening() to a cancelled SpeechRecognizer. Call it before the cancel().

speechRecognizer.stopListening();
speechRecognizer.cancel();

Upvotes: 3

Related Questions