在android中使用8位编码的AudioRecord
我制作了一个使用 AudioRecord 和 16 位编码从手机麦克风进行录音的应用程序,并且我能够播放录音。出于某些兼容性原因,我需要使用 8 位编码,但是当我尝试使用该编码运行相同的程序时,我不断收到无效的音频格式。我的代码是:
int bufferSize = AudioRecord.getMinBufferSize(11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_8BIT);
AudioRecord recordInstance = new AudioRecord(
MediaRecorder.AudioSource.MIC, 11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT,
bufferSize);
任何人都知道问题是什么?根据文档,AudioRecord 能够进行 8 位编码。
I have made an application that records from the phones microphone using the AudioRecord and 16-bit encoding, and I am able to playback the recording. For some compatibility reason I need to use 8-bit encoding, but when I try to run the same program using that encoding I keep getting an Invalid Audio Format. my code is :
int bufferSize = AudioRecord.getMinBufferSize(11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_8BIT);
AudioRecord recordInstance = new AudioRecord(
MediaRecorder.AudioSource.MIC, 11025,
AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT,
bufferSize);
Any one knows what is the problem? According to the documentation AudioRecord is capable of 8-bit encoding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你看一下源代码,它只支持little endian,但Android正在写big endian。所以你必须先转换为little endian,然后再转换为8位。这对我有用,你可以将两者结合起来:
这是一个没有字节序的简单版本
If you look at the source, it only supports little endian, but Android is writing out big endian. So you have to convert to little endian and then 8-bit. This worked for me and you can probably combine the two:
Here is a simpler version without endian