1

I am using the following code in my messenger calling app :

this.audioRecord = new AudioRecord(
                MediaRecorder.AudioSource.DEFAULT,
                Constants.SAMPLE_RATE,
                AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_PCM_16BIT,
                Constants.BUFFER_SIZE_RECORDING);

Is this the best setting for audio in calls? I have a couple of issues with echos. I tried AudioSource.MIC and VOICE_COMMUNICATION, but they perform worse. I wonder if changing any of the other variables would improve the audio quality? Any ideas about the best variable for a calling app.Also, I don't hear any audio often on Nexus 6 or pixel 2

1 Answers1

2

Audio on Android is always a tough problem because manufacturers put in different audio chips with different capabilities in all phones.

That being said VOICE_COMMUNICATION should be your best bet. It is "Microphone audio source tuned for voice communications such as VoIP. It will, for instance, take advantage of echo cancellation or automatic gain control if available."

So it should already use AcousticEchoCanceler and NoiseSuppressor to get rid of echoes and other disturbing noises. But in the end, it comes down to your use-case, if you rather want unfiltered or filtered audio.

You can also try to increase the sampling rate (Constants.SAMPLE_RATE 48000 should be best since that is the sampling rate of most modern phones) and bit depth (ENCODING_PCM_16BIT to ENCODING_PCM_FLOAT) to get a better signal. Note that supported sampling rates differ from phone to phone. To find out what your phone supports adapt the solution from audio sampling rates discussion. More information about sampling rates is covered in the Sampling Audio docs.

To the problem that you often don't hear anything, that can happen if either your gain is too low (can happen with AudioSource.MIC) or if your recorder is not ready yet (I'm making an educated guess here since I don't know your code).

Jitesh Mohite
  • 31,138
  • 12
  • 157
  • 147
leonardkraemer
  • 6,573
  • 1
  • 31
  • 54
  • Thanks so much! Very detailed. I support versions 18+ and seems like ENCODING_PCM_FLOAT works only for 21and +. Any comments on AudioFormat.CHANNEL_IN_MONO,"? and increasing buffer size recording? –  Nov 21 '17 at 16:53
  • If you use `CHANNEL_IN_STEREO`, depending on your device, one channel will be the mic for telephone and the other will be the camcorder microphone. The buffer size controls how much audio is buffered before it being processed. Therefore increasing it increases the latency but also improves stability against buffer overruns, usually you want to aim for a low value, if you go too low the `AudioRecord` will complain. – leonardkraemer Nov 21 '17 at 17:08
  • I am just using for android phones, its a calling app. No tablets or anything, just nexus,samsung and pixel devices. what do you suggest would be the ideal set from version 18+ to 26 –  Nov 21 '17 at 17:55
  • Clarification camcorder microphone == the microphone that is used for video capture. I think your settings are fine, if you want ideal audio quality for every phone you have to create separate settings for them. A different solution would be to use [SIP call](https://developer.android.com/reference/android/net/sip/SipAudioCall.html) and let the system take care of everything. If you want an ideal solution, regarding latency you must have a native implementation in the audio backend (like SIP call). – leonardkraemer Nov 21 '17 at 19:00
  • [Here is the documentation entry point](https://developer.android.com/guide/topics/connectivity/sip.html) and a [demo](https://github.com/aosp-mirror/platform_development/tree/master/samples/SipDemo) – leonardkraemer Nov 21 '17 at 20:26