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

2

7

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?

Shemeka answered 20/7, 2018 at 11:39 Comment(2)
Hi @Tan Pham Can you plz share your WebRTCAudioRecord class here so it's help me record audio during webrtc call Android?Rhoea
@Rhoea that class was in WebRTC library already. You can see here: WebRtcAudioRecordShemeka
T
1

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:

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.

Torritorricelli answered 24/10, 2019 at 17:40 Comment(0)
A
0

There are two parts for the solution:

  1. Get the raw PCM audio frames from webrtc
  2. Save them to a local file in compressed size so that it can be played out later

For the first part you have to attach the SamplesReadyCallback while creating audioDeviceManager by calling the setSamplesReadyCallback method of JavaAudioDeviceModule. This callback will give you the raw audio frames captured by webrtc's AudioRecord from the mic.

For the second part you have to encode the raw frames and write into a file. Check out this sample from google on how to do it - https://android.googlesource.com/platform/frameworks/base/+/master/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenInternalAudioRecorder.java#234

Amoebaean answered 18/5, 2022 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.