IOS 8 AVAudioRecorder change sample fomat

∥☆過路亽.° 提交于 2019-12-11 09:32:18

问题


I'm building a app where one of the functions is to record a voice message I want sample format 16-bit PCM but i cant seem to get it right. I have tried lots of diffrent settings but everytime i check the file in audacity it says 32-bit float.

This is my current recorderSettings

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

回答1:


So i found the problem i needed kAudioFormatLinearPCM instead of kAudioFormatALaw

I tried that before but then i only checked the format with audacity and it reported back 32-bit float. but after reading Dom Bryan answer I checked it again with the file command and it reported back the correct format.

so correct config would be

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



回答2:


Try looking into audacity settings. It preferences 32bit for flexibility and then suggests exporting in 16bit. Your code doesn't look wrong so try messing with audacity or different program.

Here is a link to audacity's preferences: http://audacity.sourceforge.net/onlinehelp-1.2/prefs.htm



来源:https://stackoverflow.com/questions/28835544/ios-8-avaudiorecorder-change-sample-fomat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!