我正在尝试使用AKAudioFile.exportAsynchronously将wav转换为m4a(基于此处的示例代码:https://audiokit.io/playgrounds/Playback/Exporting%20Files/)。我选择了.documents
作为我的BaseDirectory,但我一直不断收到directory <my_dir> isn't valid
错误-例如:
AKAudioFile+ProcessingAsynchronously.swift:exportAsynchronously(name:baseDir:exportFormat:fromSample:toSample:callback:):379:ERROR AKAudioFile export: directory "/var/mobile/Containers/Data/Application/20C913AD-B2F4-4F26-AAD2-0DFA0C65A886/Documents/All Of Me.mp4" isn't valid
在我看来,该URL完全合理,这是怎么回事?
答案 0 :(得分:1)
好的,遵循@jake的技巧,解决方案是在传递到AKAudioFile的exportAsynchronously(name:baseDir:exportFormat:callback:)
之前显式处理空格。我刚刚做了:
var name = String(cafURL.lastPathComponent.split(separator: ".")[0])
name = name.replacingOccurrences(of: " ", with: "%20")
let exportFile = try AKAudioFile(readFileName: "\(name).wav", baseDir: .documents)
exportFile.exportAsynchronously(name: name, baseDir: .documents, exportFormat: .m4a, callback: self.callback)