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.

binaryKarmic
  • 978
  • 7
  • 22
  • https://stackoverflow.com/questions/58230181/call-recorder-not-working-in-android-10-q – Kirguduck Feb 23 '20 at 14:41
  • 1
    The post you linked talks about MediaRecorder.AudioSource.VOICE_CALL. What I am using is MediaRecorder.AudioSource. VOICE_COMMUNICATION. I believe there is some difference in it. Also, I am not recording calls. I am recording the usual audio messages in a messaging app. Also, it is not failing on all Android 10 devices but only on a few as I mentioned earlier. – binaryKarmic Feb 24 '20 at 04:44

1 Answers1

1

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

binaryKarmic
  • 978
  • 7
  • 22
  • I faced exactly the same issue on Nokia 6.1, and indeed turning off Google Assistant helps. But what if I really want to use VOICE_COMMUNICATION audio source? I can't ask our clients to disable their assistants, and I want to be able to use audio preprocessing features such as acoustic echo cancellation. Maybe I can set up different audio fx manually, but if you got any other advice, it would be appreciated) – Alexey Ershov Apr 17 '20 at 07:30
  • 1
    I understand where you are coming from. The issue here seems like buggy implementation by the OEMs which they may or may not fix in the future, so no point on relying on it. You can do some custom fix like observe the recorded audio say after couple of seconds. If it is blank and the OS version is above 10, give user an option of turning the Assistant off or switching to slightly low quality by using VOICE_RECOGNITION. – binaryKarmic Apr 21 '20 at 12:54