IOS 8 AVAudioRecorder 改变样本格式

IOS 8 AVAudioRecorder change sample fomat

我正在构建一个应用程序,其中一个功能是录制语音消息我想要样本格式 16 位 PCM,但我似乎做不对。 我尝试了很多不同的设置,但每次我在 audacity 中检查文件时,它都会显示 32 位浮点数。

这是我当前的录音机设置

var recorderSettings = [NSObject: AnyObject]()
recorderSettings[AVFormatIDKey] = kAudioFormatALaw
recorderSettings[AVSampleRateKey] = 16000
recorderSettings[AVNumberOfChannelsKey] = 1
recorderSettings[AVLinearPCMBitDepthKey] = 16
recorderSettings[AVLinearPCMIsFloatKey] = false

尝试查看 Audacity 设置。它偏好 32 位的灵活性,然后建议以 16 位导出。您的代码看起来没有错,所以请尝试使用 audacity 或其他程序。

这是 audacity 偏好设置的 link:http://audacity.sourceforge.net/onlinehelp-1.2/prefs.htm

所以我发现问题是我需要 kAudioFormatLinearPCM 而不是 kAudioFormatALaw

我之前尝试过,但后来我只用 audacity 检查了格式,它报告了 32 位浮点数。但是在阅读 Dom Bryan 的回答后,我用文件命令再次检查了它,它报告了正确的格式。

所以正确的配置应该是

var recorderSettings = [NSObject: AnyObject]()
recorderSettings[AVFormatIDKey] = kAudioFormatLinearPCM
recorderSettings[AVSampleRateKey] = 16000
recorderSettings[AVNumberOfChannelsKey] = 1
recorderSettings[AVLinearPCMBitDepthKey] = 16
recorderSettings[AVLinearPCMIsFloatKey] = false