1
votes

I' m trying to read recorded data into the short array. I want to continue recording and reading until it is full. My code: http://pastebin.com/r6yuPn82 Unfortunately applications crashes after calling startRecording method. Errors: http://pastebin.com/9jwrPLNc May I kindly ask you to help me fixing it?

2

2 Answers

3
votes

Your AudioRecord hasn't been initialized correctly.

"Caused by: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord."

Put this in your manifest:

<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
1
votes

Make sure that you're recording before you read from your MIC to the buffer.

See answer in this post saying the the following:

 short[] audioData = new short[bufferSize];

 int offset =0;
 int shortRead = 0;

 //start tapping into the microphone
 audioRecored.startRecording();

 //start reading from the microphone to an internal buffer - chuck by chunk
 while (offset < bufferSize)
 {
    shortRead = audioRecored.read(audioData, offset ,bufferSize - offset);
        offset += shortRead;
 }

 //stop tapping into the microphone
 audioRecored.stop();