Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recorded Audio using MediaRecorder.AudioSource.VOICE_COMMUNICATION is empty on some devices with Android 10

I am recording audio for voice messages in the app using the following code.

MediaRecorder audioRecorder = new MediaRecorder();
audioRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); 
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);
audioRecorder.setOutputFile(audioRecordingFile);
audioRecorder.prepare();
audioRecorder.start();

Use of MediaRecorder.AudioSource.VOICE_COMMUNICATION instead of MediaRecorder.AudioSource.MIC) is very helpful in recording pre-processed clean audios.

But, recently I found some issues in which the recorded files are empty are being reported on a few devices which were recently updated to Android 10. It should be noted that not all Android 10 devices have these issues, only a few i.e Nokia 6.1 and Mi A2.

There is no error or exception but just empty audio output files.

If I use MediaRecorder.AudioSource.MIC) then the issue is not seen.

I found the following information related to Android 10 and VOICE_COMMUNICATION The Android 10 release includes the following requirements for capture with VOICE_COMMUNICATION.

Based on this I checked the availability of AcousticEchoCanceler,AutomaticGainControl and NoiseSuppressor using the following code.

AcousticEchoCanceler.isAvailable()
AutomaticGainControl.isAvailable()
NoiseSuppressor.isAvailable()

And found the same result on Mi A2 and OnePlus 6 with Android 10. Both of the devices show AcousticEchoCanceler and NoiseSuppressor as available and AutomaticGainControl as not available.

Since the issue is not present on all Android devices, I don`t want to fall back on using MediaRecorder.AudioSource.MIC). At the same time, there is no error, exception or differentiating factor which tells me when to fall back on MediaRecorder.AudioSource.MIC).

UPDATE: The issue gets resolved when Google Assistant is turned off on Mi A2. This might be the pointer : https://developer.android.com/guide/topics/media/sharing-audio-input

Any help regarding this is appreciated.

like image 744
binaryKarmic Avatar asked Feb 21 '20 11:02

binaryKarmic


1 Answers

I ended up using MediaRecorder.AudioSource.VOICE_RECOGNITION instead of MediaRecorder.AudioSource.VOICE_COMMUNICATION on all android versions.

We ended up taking samples on 15+ different devices and found out that MediaRecorder.AudioSource.VOICE_RECOGNITION works best with the majority devices including high-end and mid-range phones.

As per my understanding, the original issue faced on few devices on some devices seems like implementation issues by the OEMs with respect to Android 10 and VOICE_COMMUNICATION https://source.android.com/devices/audio/implement-pre-processing

like image 102
binaryKarmic Avatar answered Oct 16 '22 23:10

binaryKarmic