我正在尝试使用以下设置使用 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];
最佳答案
在 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)")
}
https://stackoverflow.com/questions/10914888/
相关文章:
amazon-web-services - 将本地文件放入 Amazon EBS 卷的最快方法是什么
azure - 防止交叉链接到 Azure Blob 存储上的图像
ruby-on-rails-3 - 在 Ruby on Rails 中,有没有一种方法可以使用 RS
ruby-on-rails - 尝试使用 Google Calendar API 时出现 "Miss
asp.net-mvc-3 - 添加 google recaptcha 服务器端验证 MVC3
asynchronous - 将 Openssl 与异步 Winsock 结合使用
ruby-on-rails-3 - 环境与 WickedPDF 和 Heroku 冲突