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