-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for AMR format #264
Comments
I think this is a good idea and it would be pretty easy to add. However, I don't currently plan on adding it because AMR is still patented and I live in a pretty litigious country. As far as I'm aware, only the decoder can be used royalty-free, not the encoder. |
My preference is lossless, but I think supporting amr would be great (if possible in the future) for people with concerns about file storage because the quality is excellent for such a low bitrate. |
IIRC, Android has an AMR encoder builtin, so patents should be covered by the phone vendor already. Just don't add your own encoder. |
That was what I thought before too, but I don't think that's a safe assumption to make anymore. Last year, a bunch of Linux distros were forced to remove support for hardware H.264/H.265 video decoding/encoding despite GPU manufacturers having already paid for the patents. I'm not willing to take the risk--I'll just wait for the patents to expire (which, if I remember correctly, is slated for some time in 2024). |
@chenxiaolong In the meantime, would it be possible to add the open-source OGG/Speex audio format to achieve better compression for voice? Speex supports mono/stereo and a bitrate range of 2 kbps to 44 kbps. It could be superior to AMR for call recording as it would allow for the creation of small files with a quality sufficient for archiving phone calls. Thank you. |
I hadn't heard of Speex. That looks like a very nice format. Unfortunately, it doesn't look like Android ships with an encoder for it: https://developer.android.com/guide/topics/media/platform/supported-formats. I currently don't have any plans in the near future to add/bundle external codecs. In the meantime, I'd suggest using OGG/Opus with a sample rate of 16 kHz (**) and bit rate of 9 kbps if you're aiming for small file sizes. BCR's default bit rate of 48 kbps aims for very good quality without being lossless, but Opus is able to compress speech very well at low bit rates: https://wiki.hydrogenaud.io/index.php?title=Opus#Speech_encoding_quality (**): BCR defaults to 48 kHz because some devices crash or fail with any other sample rate. If your device works with 16 kHz, it's strongly recommended because anything higher than 16 kHz doesn't capture any more useful data. The sample rate of the actual underlying phone call is 16 kHz (or even 8 kHz if your carrier doesn't support "HD audio"). |
this is not a related bug report, just a question: so the lte/4g/5g audio is in amr format? if so then PCM is the original format of the audio (because we can't access the first AMR file)? can these two be combined? I am trying to see what the highest fidelity I can achieve for recorded audio of conversation. |
Yep. The data going "over the wire" is AMR. LTE uses AMR-WB and it looks like 5G uses AMR-WB+. The encoding and decoding both happen in the modem. If the call gets recorded, Android only sees PCM.
The call recording audio stream comes from the modem, where both sides of the call are already merged together into a single stream. The received audio is always decoded from AMR -> PCM first. For your own audio, I don't know if the modem combines the microphone's PCM stream directly or if it does something like PCM (microphone) -> AMR (to send over the wire) -> PCM (recording). It probably depends on the device. This can be tested by placing the phone next to something that AMR handles poorly, like music, and seeing if the microphone audio is clear in the recording.
If you want the best fidelity, pick FLAC or WAV with a 48 kHz sample rate. Both options are equivalent and are an exact copy of the audio as Android sees it. |
thanks for great answers. wav/pcm is that audio stream from modem? then how is my outgoing audio (from mic) gets in there? flac is losless if I recall correctly. what are the levels then? just cpu/ram usage and size related? what about sample rate? why I can specially sample rate for wav/pcm if it is from modem (the modem itself (or the radio/lte)) does the sampling) |
Yes
That is done by the modem. It combines the incoming and outgoing audio and passes the resulting PCM stream to Android.
That is correct. The audio is identical at every level. The high levels just have smaller file sizes. Just about every device from the past few years should have no trouble using the highest compression level. In my testing, the CPU usage is around 20-30% of one core.
Every device I've seen uses a native sample rate of 48 kHz for the call recording audio stream. BCR doesn't have a "native" option in the settings because querying the native sample rate requires a call to be active and it can take several seconds on some devices, causing the start of the call audio to be lost. If you pick any other rate, the audio is resampled. |
I just did a quick test. On my Pixel 8 Pro, the outgoing audio from the microphone goes through a bunch of audio processing to remove background noise before being merged with incoming audio into the call recording audio stream. The modem is definitely not recording the raw microphone audio. (Other devices might be different.) |
so a wav/pcm with 48Khz and a flac with 48khc are the same ? not in size but in sound quality. |
Yep, that's correct. |
It would be great if you add support to record in AMR format. This is a standard format for recording and can be recognized by many third-party apps.
BCR doesn't have a built-in player, so it would be very helpful to support a format that can easily be managed by third-party recording and playing apps.
Thank you!
The text was updated successfully, but these errors were encountered: