15

I have the following problem: I use SpeechRecognizer to identify a few words. I use the

public void onResults

method to destroy the SpeechRecognizer.

Right after the destruction I initialize an AudioRecord and start recording from the mic. This leads to the following error in my logcat:

12-09 00:44:01.976: E/AudioRecord(21185): start() status -38

No exception is thrown in my code. The AudioRecord just does not start properly. I am assuming that the SpeechRecognizer does not release the microphone quickly enough, because if I add a Thread.sleep(200) in front of the initialization of the AudioRecord, I do not experience this issue.

This solution is very bad for obvious reasons. Thus, I have the following question:

How do I check whether the AudioRecord is initialized properly? (I do not get an exception in my code.)

_audioRecord.getState() == AudioRecord.STATE_UNINITIALIZED

is false as well.

Or how do I check whether SpeechRecognizer released the microphone properly?

Thanks a lot!

user3081081
  • 151
  • 1
  • 3

4 Answers4

9

You need to make sure you issue audioRecord.stop(); and audioRecord.release(); in your onPause() or similar methods. If you don't, the next time you run the app, you won't get access to the device, and you'll get start() status -38

troy.unrau
  • 1,142
  • 2
  • 12
  • 26
1

I was having a similar problem to this AudioRecord start() error status -38 what i eventually did was loop over the possible configurations of the audio recorder like the answerer said in this question AudioRecord object not initializing I like this method since it doesn't matter what device you run it on it will eventually find a configuration that it likes.

Community
  • 1
  • 1
mkrinblk
  • 896
  • 9
  • 21
  • Hi, my for loop always chooses 16000 as a samplerate, but AudioRecord initializes properly only the first time. What can it be? – Josh Aug 27 '17 at 18:49
0

I checked recording state by using audioRecord.getRecordingState() as Michael commented. Normally after audioRecord.startRecording();, recordingState becomes RECORDSTATE_RECORDING. If state is not RECORDSTATE_RECORDING, I will close app.

audioRecord.startRecording();
int recordingState = audioRecord.getRecordingState();
Log.i(VoiceRecorder.class.getSimpleName(), "RecordingState() after startRecording() = " + String.valueOf(recordingState));
if (recordingState != AudioRecord.RECORDSTATE_RECORDING) {
    Log.i(VoiceRecorder.class.getSimpleName(), "AudioRecord error has occured. Reopen app.");
    System.exit(0);
}
Aung Thu Win
  • 31
  • 1
  • 6
0

I had a different app that was probably running the background and didn't release the recording device. You also need to make sure all other apps are closed (using the switch between apps > CLEAR ALL).

D.Ginzbourg
  • 490
  • 7
  • 22