如何在swift中创建一个处理格式为16的音频文件?

问题描述 投票:0回答:1

这是我的代码,processingFormat始终是,如何使其成为Int16?

   `let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!

    let audioURL = documentDirectory.appendingPathComponent("recording_\(UUID().uuidString).wav")
    let int16Format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 16000, channels: 1, interleaved: true)!

    do {
        audioFile = try AVAudioFile(forWriting: audioURL, settings: int16Format.settings)
        if let processingFormat = audioFile?.processingFormat {
            print("Processing format: \(processingFormat)")
        }
    } catch {
        print("Error creating audio file: \(error.localizedDescription)")
    }
ios iphone swift5
1个回答
0
投票

我明白了!应该是

init(forWriting:URL,设置:[String:Any],commonFormat:AVAudioCommonFormat,交错:Bool)

© www.soinside.com 2019 - 2024. All rights reserved.