如何在 iPhone 上录制 AMR 音频格式?
录音机不需要未压缩的线性 PCM 音频。 压缩的 AMR
就可以了。 为录制音频而构建的 iPhone 框架非常简单,但我发现的用于设置音频格式(来自 Apple)的唯一示例使用 LinearPCM。 我尝试过各种其他值的组合,但似乎没有任何效果。
有人有实际记录 AMR
的代码吗?
编辑: AMR 格式是设置数据类型的选项之一,但其他选项(数据包大小、帧大小等)无论我设置什么,似乎都不匹配。
编辑:这是我的 PCM 版本:
/*
If we want to use AMR instead of PCM:
AMR Format:
Sampling Frequency: 8 kHz/13-bit (160 samples for 20 ms frames), filtered to 200-3400 Hz
eight source codecs : 12.2, 1.2, 7.95, 7.40, 6.70, 5.90, 5.15, 4.75 kbit/s
generated frame length: 244, 204, 159, 148, 134, 118, 103, 95 bits per frame
*/
format->mFormatID = kAudioFormatLinearPCM;
format->mSampleRate = 8000.0; //8 kHz
format->mFramesPerPacket = 1; //1 frame per packet
format->mChannelsPerFrame = 1; //Mono
format->mBytesPerFrame = 2; //8/bits per frame (round up)
format->mBytesPerPacket = 2; //Same as bytes per frame
format->mBitsPerChannel = 16; //16-bit audio
format->mReserved = 0; //always 0
format->mFormatFlags = kLinearPCMFormatFlagIsBigEndian |
kLinearPCMFormatFlagIsSignedInteger |
kLinearPCMFormatFlagIsPacked;
A voice recorder doesn't need uncompressed Linear PCM audio. Compressed AMR
would do fine. The iPhone framework built for recording audio is simple enough, but the only examples I've found for setting up the audio format (which come from Apple) use LinearPCM. I've tried various other combinations of values, but can't seem to get anything to work.
Does anybody have any code that actually records AMR
?
Edit:
The AMR format is one of the options for setting the data type, but the other options (packet size, frame size, etc.) don't seem to match up no matter what I set them to.
Edit: Here's what I have for the PCM version:
/*
If we want to use AMR instead of PCM:
AMR Format:
Sampling Frequency: 8 kHz/13-bit (160 samples for 20 ms frames), filtered to 200-3400 Hz
eight source codecs : 12.2, 1.2, 7.95, 7.40, 6.70, 5.90, 5.15, 4.75 kbit/s
generated frame length: 244, 204, 159, 148, 134, 118, 103, 95 bits per frame
*/
format->mFormatID = kAudioFormatLinearPCM;
format->mSampleRate = 8000.0; //8 kHz
format->mFramesPerPacket = 1; //1 frame per packet
format->mChannelsPerFrame = 1; //Mono
format->mBytesPerFrame = 2; //8/bits per frame (round up)
format->mBytesPerPacket = 2; //Same as bytes per frame
format->mBitsPerChannel = 16; //16-bit audio
format->mReserved = 0; //always 0
format->mFormatFlags = kLinearPCMFormatFlagIsBigEndian |
kLinearPCMFormatFlagIsSignedInteger |
kLinearPCMFormatFlagIsPacked;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
AMR 编解码器不支持在 iPhone 上进行编码/录制,尽管支持播放:这就是 kAudioFormatAMR 常量存在的原因。
官方api说支持的编码格式有:
您可以尝试其中一种格式或使用开源 AMR 编码器作为 goldenmean 建议。
编辑:更新了官方 API 链接
AMR codec is NOT supported for encoding/recording on the iPhone, albeit it is supported for playback: this is the reason the kAudioFormatAMR constant exists.
Official api says that supported encoding formats are:
You may try one of these formats or use an open source AMR encoder as goldenmean suggests.
edit: Updated Official api link
更新 olegueret 到官方文档的链接(为什么他们隐藏这些东西?)
http://developer.apple.com/library/ios/#qa/qa2008/qa1615.html
To update olegueret's link to the official documentation (why do they hide this stuff?)
http://developer.apple.com/library/ios/#qa/qa2008/qa1615.html
我猜我的 iPhone 录音机应用程序不支持 AMR 编解码器格式。
也许可以尝试将一些开源的 AMR 编码器实现集成到苹果的 iPhone 应用程序框架中,并尝试使录音机以 AMR 编码格式存储音频。 (我不知道苹果的 NDA/许可证是否允许这样做)。
-广告
I guess AMR codec format is not supported my iPhone voice recorder app.
May be one can try integrating some open-source, implementation of AMR encoder into the apples' iPhone application framework and try making the voice recorder store the audio in AMR encoded format. (i dont know if thats allowed by apple by their NDA/license).
-AD
您可以将音频录制到未压缩的线性 PCM 缓冲区(循环或环形)中,并在另一个线程中使用您自己的 AMR(或其他)压缩引擎转换此缓冲区中的数据,然后将压缩的音频数据保存到文件中。
You can record audio to a uncompressed Linear PCM buffer (circular or ring), and, in another thread, convert data in this buffer, using your own AMR (or other) compression engine, before saving the compressed audio data to a file.