How to record microphone to more compressed format during WebRTC call on Android?

I have an app calling using WebRTC. But during a call, I need to record microphone. WebRTC has an object WebRTCAudioRecord to record audio but the audio file is so large (PCM_16bit). I want to record but to a smaller size.

I've tried MediaRecorder but it doesn't work because WebRTC is recorded and MediaRecorder does not have permission to record while calling.

Has anyone done this, or have any idea that could help me?


Webrtc is considered as comparatively much better pre-processing tool for Audio and Video.

Webrtc native development includes fully optimized native C and C++ classes, In order to maintain wonderful Speech Quality and Intelligibility of audio and video which is quite interesting.

Visit Reference Link: https://github.com/jitsi/webrtc/tree/master/examples regularly.


As Problem states;

I want to record but smaller size. I've tried MediaRecorder and it doesn't work because WebRtc is recorded and MediaRecorder has not permission to record while calling.


First of all, to reduce or minimize the size of your recorded data (audio bytes), you should look at different types of speech codecs which basically reduce the size of recorded data by maintaining sound quality at a level. To see different voice codecs, here are well-known speech codecs as follows:

  • OPUS

  • SPEEX

  • G7.11 (G-Series Speech Codecs)

As far as size of the audio data is concerned, it basically depends upon the Sample Rate and Time for which you record a chunk or audio packet.

Supppose time = 40ms ---then---> Reocrded Data = 640 bytes (or 320 short)

Size of recorded data is **directly proportional** to both Time and Sample rate.

Sample Rate = 8000 or 16000 etc. (greater the sample rate, greater would be the size)

To see in more detail visit: fundamentals of audio data representation. But Webrtc mainly process 10ms audio data for pre-processing in which packet size is reduced up to 160 bytes.


Secondly, If you want to use multiple AudioRecorder instances at a time, then it is practically impossible. As WebRtc is already recording from microphone then practically MediaRecorder instance would not perform any function as this answer depicts audio-record-multiple-audio-at-a-time. Webrtc has following methods to manage audio bytes such as;

 1. Push input PCM data into `ProcessCaptureStream` to process in place.
 2. Get the processed PCM data from `ProcessCaptureStream` and send to far-end.
 3. The far end pushed the received data into `ProcessRenderStream`.

I have maintained a complete tutorial related to audio processing using Webrtc, you can visit to see more details; Android-Audio-Processing-Using-Webrtc.