使用AVAudioRecorder录制WAV格式文件?

时间:2012-06-06 13:10:55

标签: iphone ios avaudiorecorder

我正在尝试使用以下设置使用AVAudiorecorder录制wav文件。创建的文件在我的Mac和iPhone上运行正常但是当我将它邮寄到黑莓设备并尝试从那里播放时它表示格式不受支持..我可能做错了什么?  我相信我在初始化audiorecorder的设置时遗漏了一些内容,所以我只发布设置词典

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];

1 个答案:

答案 0 :(得分:0)

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)")
        }