Im working on a personal assistant using pocketsphinx speech recognizer in android. This is the way my app works every time a special word is heard the personal assistant will answer back and do a task. I have been having some problems with the releasing of the microphone. I dont know if it is a bug. It only happens sometimes when I close the application the microphone is still looking for that word and answering using text to speech. Even though screen is off. When I tried to record a video it says microphone is used by another application. So I have to open my app again and close the app to release the microphone. In my knowledge the only lifecycles to release resources are onStop, onPause, and onDestroy. It cannot be my phone that is malfunctioning I have tested the app with two different phones and still sometimes it happens in bot of them. Any help would be appreciated. This is the way Im releasing the microphone, camera and the text to speech. Thanks in advance
private edu.cmu.pocketsphinx.SpeechRecognizer recognizer;
@Override
public void onPause() {
super.onPause();
if (tts != null) {
tts.shutdown();
}
if (camera != null) {
camera.release();
camera = null;
}
if (recognizer != null) {
recognizer.stop();
recognizer.cancel();
recognizer.shutdown();
recognizer = null;
}
}
@Override
protected void onStop() {
super.onStop();
if (tts != null) {
tts.shutdown();
}
if (camera != null) {
camera.release();
camera = null;
}
if (recognizer != null) {
recognizer.cancel();
recognizer.shutdown();
recognizer = null;
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (tts != null) {
tts.shutdown();
}
if (camera != null) {
camera.release();
camera = null;
}
if (recognizer != null) {
recognizer.cancel();
recognizer.shutdown();
}
}