Android AudioRecord 和 AudioTrack 编解码器选项?
我目前在 Android 中使用 AudioTrack 和 AudioRecord 类。
我使用纯 PCM 数据,但我想知道其他编解码器的选项是什么?
来自此页面看来我只能使用 AMR 窄带进行编码和解码?
我当前设置音频类如下:
arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
buffersize);
atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
buffersize,
AudioTrack.MODE_STREAM);
所以我的问题是如何将编码从 PCM 更改为其他受支持的编解码器之一?
当我尝试更改 AudioFormat 上的 ENCODING_PCM_16BIT 时,我只获得默认或无效编码的选项以及 PCM 选项。
如果有人知道这里的任何帮助,那么任何关于 Android 上音频编码和解码教程的链接都会很棒,非常感谢。
谢谢
编辑:我已将代码更改为以下内容:
arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
**MediaRecorder.AudioEncoder.AMR_NB**,
buffersize);
atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
**MediaRecorder.AudioEncoder.AMR_NB**,
buffersize,
AudioTrack.MODE_STREAM);
代码运行正常,但我想知道它是否实际上将音频编码为 AMR_NB 以及这是否不是正确的方法?
我在使用原始 PCM 时遇到缓冲区溢出问题,但自从使用新代码并使用 MediaRecorder.AudioEncoder.AMR_NB 而不是 AudioFormat.PCM 后,没有出现缓冲区溢出问题
I currently use the AudioTrack and AudioRecord classes in Android.
I use the pure PCM data but I was wondering what my options are for other codecs?
From this page it seems I can only encode and decode using AMR narrowband?
I currently set up the Audio classes as follows:
arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
buffersize);
atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
buffersize,
AudioTrack.MODE_STREAM);
So my question is how do I change the encoding from PCM to one of the other supported codecs?
When I try to change ENCODING_PCM_16BIT on AudioFormat I only get the options of default or invalid encoding along with the PCM options.
Any links to tutorials on encoding and decoding audio on Android would be great if anyone knows of any or any help here greatly appreciated.
Thanks
EDIT: I have changed my code to the following:
arec = new AudioRecord(MediaRecorder.AudioSource.MIC,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
**MediaRecorder.AudioEncoder.AMR_NB**,
buffersize);
atrack = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
**MediaRecorder.AudioEncoder.AMR_NB**,
buffersize,
AudioTrack.MODE_STREAM);
The code runs properly but I'm wondering does it actually encode the Audio as AMR_NB and if this is not a proper way to do it?
I was getting a buffer overflow when using raw PCM but none have appeared since using the new code with the MediaRecorder.AudioEncoder.AMR_NB used instead of the AudioFormat.PCM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如
AudioRecord
和AudioTrack
的文档所述:您只能使用 8 位和 16 位 PCM。如果您想要其他格式的音频,请不要使用
AudioRecord
和AudioTrack
(尝试MediaRecorder
和MediaPlayer
)或者您必须使用自己的代码(可能利用 NDK)对其进行转码。AudioRecord
和AudioTrack
专为 OpenCORE 多媒体引擎不支持相关音频的情况而设计,因为它不是受支持的编解码器或不受支持的流协议(例如,SIP)。As the documentation states for
AudioRecord
andAudioTrack
:you can only work with 8-bit and 16-bit PCM. If you want audio in other formats, either don't use
AudioRecord
andAudioTrack
(tryMediaRecorder
andMediaPlayer
) or you will have to transcode it using your own code, possibly leveraging the NDK.AudioRecord
andAudioTrack
are designed specifically for cases where the audio in question is not supported by the OpenCORE multimedia engine, either because it's not a supported codec or not a supported streaming protocol (e.g., SIP).