Android AudioRecord which settings to record call
Asked Answered
R

3

10

I use AudioRecord class to record the voice during a call.

I am intererested to record only the voice of the person who owns the phone ( from the microphone). During the recording I would like to do some audio processing but this is offtopic for now.

Android has the following AudioSources options:

  • MediaRecorder.AudioSource.VOICE_CALL
  • MediaRecorder.AudioSource.MIC
  • MediaRecorder.AudioSource.VOICE_UPLINK
  • MediaRecorder.AudioSource.VOICE_DOWNLINK

Can you explain what is the differences among them. Ok MIC is obvious but VOICE_CALL vs VOICE_UPLINK vs VOICE_DOWNLINK ?

Also I should choose a sample rate ( 8000Hz, 16000Hz, 2250Hz, 44100Hz ). Can you please tell me what sample rate to choose and why?

For audio format I chose AudioFormat.ENCODING_PCM_16BIT but it also has: - AudioFormat.ENCODING_DEFAULT - AudioFormat.ENCODING_INVALID - AudioFormat.ENCODING_PCM_8BIT

Finally is how many channels should I use and why? ( AudioFormat.CHANNEL_IN_STEREO or AudioFormat.CHANNEL_IN_MONO )

Rebirth answered 26/4, 2012 at 9:5 Comment(5)
call recording is very difficult in android.In better words (My personal experience) its not possible..just google.u can see that many documents telling that it's not possible.because call recording is in the base layer of android os.so we can not edit that part.its in binaryKarachi
In what version of android you have tried? I think that the Api says that it supports it (official) so I would give this a try.Rebirth
when i tried then it will record only for few seconds...recording supporting only for some mobiles..check these links thes are useful for u..https://mcmap.net/q/1161542/-recording-phone-calls-on-android https://mcmap.net/q/1161543/-android-call-recordingKarachi
Thanks, maybe you know what is the difference betwwen uplink an downlink?Rebirth
if u are making a call down link is the other persons sound channel and uplink is your sound channel(voice)Karachi
L
12

You should always aim to use 44100 as sample rate since it is the only sample rate that is guaranteed to work according to google.

"the sample rate expressed in Hertz. 44100Hz is currently the only rate that is guaranteed to work on all devices, but other rates such as 22050, 16000, and 11025 may work on some devices." Dev site

As for stereo versus mono, use mono.

"describes the configuration of the audio channels. See CHANNEL_IN_MONO and CHANNEL_IN_STEREO. CHANNEL_IN_MONO is guaranteed to work on all devices." Dev site

Finally: 8bit pcm vs 16bit pcm: Use 16bit pcm,

"Audio data format: PCM 16 bit per sample. Guaranteed to be supported by devices." Dev site

Just remember to use a short[] buffer instead of byte buffer when using 16bit. Since 16bit is 2 bytes you will have to combine two entries in the buffer at a time:

byte][]{sample_1_upper, sample_1_lower, sample_2_upper, sample_2_lower,...,sample_n_lower} However if you'll use a short[]buffer:
short[]{sample1, sample2, ..., sample3}

I've never tried to record a call, but if the OS doesn't bind the MIC source you could probably record from it. Since you're recording from the microphone you should only get the users voice.

Latea answered 17/7, 2012 at 9:12 Comment(3)
You should inform the Android documentation then which still clearly states that: " 44100Hz is currently the only rate that is guaranteed to work on all devices, but other rates such as 22050, 16000, and 11025 may work on some devices."Latea
Documentation is not true, some devices doesnt support 44100Brucie
Hello in my case i want both side recording but in some mobile like Samsung S8plusEdhe, S7edge is not working they only record my voice not other side voice whom i talking on phone.Rosemaria
C
11

Can you explain what is the differences among them. Ok MIC is obvious but VOICE_CALL vs VOICE_UPLINK vs VOICE_DOWNLINK ?

VOICE_UPLINK: The audio transmitted from your end to the other party. IOW, what you speak into the microphone (plus surrounding noise depending on whether noise suppression is used and how well it performs).

VOICE_DOWNLINK: The audio transmitted from the other party to your end.

VOICE_CALL: VOICE_UPLINK + VOICE_DOWNLINK.

Colonic answered 26/10, 2012 at 16:2 Comment(1)
Hello in my case i want both side recording but in some mobile like Samsung S8plusEdhe, S7edge is not working they only record my voice not other side voice whom i talking on phone.Rosemaria
L
2

A bit late but you can query the audio device to find out what it can do;

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
String sampleRate =  audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
String sampleBufferSize = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
int bufferSize = AudioRecord.getMinBufferSize(Integer.parseInt(sampleRate), AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
Labors answered 2/3, 2016 at 11:18 Comment(4)
Hello in my case i want both side recording but in some mobile like Samsung S8plusEdhe, S7edge is not working they only record my voice not other side voice whom i talking on phone.Rosemaria
In the last few version of Android the manufactures were encouraged to build their phones with the Voice.Call recording both sides of the call (some messed it up and used Voice.Comm). At one point nearly every phone supported it and a large number of third parties brought out call recording systems (at great cost and time) and enrolled many users THEN Android just disabled it..... Completely unrelated but at about the same time Samsung (largest Android device producer) brought out their own call recording solution (which can bypass the disabling as they make the phones).Labors
@RecycledSteel So there is a complete mess of which device supports it, and how. Is there some place that covers all of the configurations needed for each? In my test on OnePlus 2, it records incoming calls fine using VOICE_CALL audio source and that's it, but for outgoing calls it records only from MIC audio source, and won't record the voice from the other side (unless speaker is turned on). Somehow this app has it covered: play.google.com/store/apps/… . Any way to know how?Gumshoe
In short you can tap the data from the Audio chips/drivers themselves, this is hard work (is low level C mostly), however, more and more this "workaround" is being patched up so it will not work forever.Labors

© 2022 - 2024 — McMap. All rights reserved.