1

我正在使用 SpeechRecognizer 类。

这是我的代码:

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

问题是我无法暂停和恢复它。我已经尝试过:

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

但它仍然在听。

4

1 回答 1

2

您不能对已取消的 SpeechRecognizer 调用 stopListening()。在 cancel() 之前调用它。

speechRecognizer.stopListening();
speechRecognizer.cancel();
于 2012-07-03T07:07:54.647 回答