AudioKit 5.0b - 无法将 PCM 转换为 m4a

问题描述

我正在使用 AudioKit 5.0 beta 来规范化一个简短的录音(3 秒)并将其转换为 m4a。

原始输入文件为wav,16000采样率,1声道。我将其读入缓冲区,对缓冲区进行标准化,然后将结果输出到 32 位 wav 文件。剩下的步骤是将输出文件转换为最终格式,必须是 16 位 m4a。

    func processRecording(resultHandler: @escaping (AudioProcessingResult) -> Void) {
        var normalizedFile: AVAudioFile!

        let originalFile = try! AVAudioFile(forReading: FileManager.audioTempFileURL)
        let buffer = AVAudioPCMBuffer(pcmFormat: originalFile.processingFormat,frameCapacity: AVAudioFrameCount(originalFile.length))!
        try! originalFile.read(into: buffer)
        let normalizedBuffer = buffer.normalize()!
        normalizedFile = try! AVAudioFile(url: FileManager.normalized32AudioTempFileURL,fromBuffer: normalizedBuffer)
        normalizedFile = nil // let file go out of scope to close it

        var converterOptions = FormatConverter.Options()
        converterOptions.format = "m4a"
        converterOptions.bitDepth = UInt32(16)
        converterOptions.channels = UInt32(1)
        converterOptions.bitRate = 64000
        let finalAudioConverter = FormatConverter(inputURL: FileManager.normalized32AudioTempFileURL,outputURL: FileManager.processedAudioFileURL,options: converterOptions)
        // convert to final format and send to result handler.
        finalAudioConverter.start { error in
            if let error = error {
                resultHandler(.error(error.localizedDescription))
            } else {
                resultHandler(.success)
            }
        }
    }
}

标准化效果很好,标准化的文件输出正常,但使用 FormatConverter 将该文件转换为 16 位 m4a 失败。我收到一条 AudioCodecInitialize failed 消息到控制台,它抛出 Cannot Encode Media 错误。

但是,如果我指定 converterOptions.format = "wav" 而不是 "m4a" 效果很好。

我在 MacOS 11.1 上使用 Xcode 12.3,为 iOS 14.x 构建。

任何想法可能是什么问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...