用 AVAudioRecorder 录制 WAV 格式文件?
Posted
技术标签:
【中文标题】用 AVAudioRecorder 录制 WAV 格式文件?【英文标题】:Recording WAV format file with AVAudioRecorder? 【发布时间】:2012-06-06 13:10:55 【问题描述】:我正在尝试使用以下设置使用 AVAudiorecorder 录制 wav 文件。创建的文件在我的 Mac 和 iPhone 上可以正常播放,但是当我将它邮寄到黑莓设备并尝试从那里播放时,它说格式不受支持..我可能做错了什么? 我相信我在初始化录音机的设置时遗漏了一些东西,所以我只发布设置字典
NSDictionary *settings = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0],AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatLinearPCM],AVFormatIDKey,// kAudioFormatLinearPCM
[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
[NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
[NSNumber numberWithInt: AVAudioQualityMedium],AVEncoderAudioQualityKey,nil];
【问题讨论】:
链接对你有帮助***.com/questions/570430/… 【参考方案1】:在 2021 使用 swift 5 更容易实现这一目标,
let fileURL: URL =
let src = "abc.wav"
return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent(src)
()
let recordSettings: [String : Any] = [AVFormatIDKey: Int(kAudioFormatLinearPCM),
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 1,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue ]
do
audioRecorder = try AVAudioRecorder(url: fileURL, settings: recordSettings)
audioRecorder?.prepareToRecord()
catch
print("Error creating audio Recorder. \(error)")
【讨论】:
以上是关于用 AVAudioRecorder 录制 WAV 格式文件?的主要内容,如果未能解决你的问题,请参考以下文章
如何同时录制使用 AVPlayer 和 wav 文件播放的歌曲?
Swift AVAudioPlayer 不会播放用 AVAudioRecorder 录制的音频