3

我正在尝试使用以下设置使用 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];
4

1 回答 1

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)")
        }
    
于 2021-07-01T13:05:11.813 回答