0

I have a problem with the AudioRecord class in Android. In my application I initialize the class using:

recorder = new AudioRecord(
   audioSource,    // currentAudioSource,
   sampleRate,     // SAMPLE_RATE_IN_8KHZ,
   channelCount,   // CHANNEL,
   ENCODING,
   bufferSize      // minBufferSize
);

And then I start the audio recording with:

recorder.startRecording();

I capture the audio received from the Audio Record with the following instructions:

Thread.sleep(40);
sampled = this.recorder.read(samples, 0, currentBufferSize, AudioRecord.READ_NON_BLOCKING);

I have to use the non-blocking read because I don't want the application to hang waiting for audio and for this I have introduced a 40 ms sleep.

My declared permissions are as follows:

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" tools:ignore="ProtectedPermissions" />

The algorithm works correctly on all smartphones on which I have tested it (Android 7, Android 8 and most recent versions of Android). But it does not work on a Samsung "Galaxy Tab A6" tablet with Android 8.1.0 and on a Samsung "Galaxy Tab 2" tablet with Android 7.0.

If I use the read blocker, the audio is captured correctly by the microphone of all devices. Do you have any ideas to solve the problem? I've been trying to solve it for a few days, but I haven't found anything.

Thank you all. Michele

1
  • I also tried with a Huawei Tablet with Android 10 and it works correctly. I'm starting to think it's just a problem with Samsung's tablets. Commented Jul 20, 2022 at 13:25

1 Answer 1

0

I found where my algorithm was failing. Some time ago an algorithm was introduced that did a check on the length of the bytes returned by the read (non-blocking). After 5 failed cycles, the AudioManager object was recreated.

On the tablet in question, the read (non-blocking) began to return audio from the sixth cycle onwards, therefore a loop was created in which the AudioManager was recreated several times without ever transmitting the audio.

Fixed by increasing the number of possible empty cycles.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.