To resolve this issue, change the size of the AudioRecord buffer to 2 times the minimum buffer size.
You can use the static method AudioRecord.getMinBufferSize() . This will give you the minimum buffer size that will be used for your current format.
The syntax of the getMinBufferSize () method is:
public static int getMinBufferSize ( int sampleRateInHz, int channelConfig, int audioFormat)
Anything less than this number will fail to create an AudioRecord object.
You had to reduce the size of the buffer so as not to overload the audio subsystem with data requirements.
Remember to put overridden methods ( @Override ) for the audioRecord callback as follows:
private AudioRecord.OnRecordPositionUpdateListener updateListener = new AudioRecord.OnRecordPositionUpdateListener(){ @Override public void onPeriodicNotification(AudioRecord recorder){ int result = aRecorder.read(buffer, 0, buffer.length); } @Override public void onMarkerReached(AudioRecord recorder) {} };
I recommend reading the post: Android Sound Recording, Part 2
Another thing you could try is to use streams when writing and another process on the written bytes, thereby avoiding too much congestion on the main user interface thread.
Open source sample code for this approach: musicg_android_demo
Mark this post for more - android-audiorecord-class-process-live-mic-audio-quickly-set-up-callback-func
source share