我正在使用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();
但是它仍然在听。
最佳答案
您不能将stopListening()调用到已取消的SpeechRecognizer。在cancel()之前调用它。
speechRecognizer.stopListening();
speechRecognizer.cancel();