0

I'm trying to use AKAudioFile.exportAsynchronously to convert wav to m4a (based on the sample code here: https://audiokit.io/playgrounds/Playback/Exporting%20Files/). I've chosen .documents as my BaseDirectory, but I just keep getting directory <my_dir> isn't valid errors — e.g.:

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

That URL looks completely reasonable, to me, so what's up?

jbm
  • 1,248
  • 10
  • 22
  • 1
    Should `All Of Me.mp4` have space chars like `All\ Of\ Me.mp4`? – jake Jun 11 '19 at 02:24
  • Well, that's certainly a reasonable question, but it seems strange to me that the library wouldn't handle spaces gracefully. I can certainly try explicitly addressing spaces though. – jbm Jun 11 '19 at 02:41
  • Okay, yes, it looks like I needed to handle the spaces explicitly when passing `name` into `exportFile.exportAsynchronously(name:baseDir:exportFormat:callback:)`. – jbm Jun 11 '19 at 03:25

1 Answers1

1

Okay, following @jake's tip, the solution was to handle the spaces explicitly before passing into AKAudioFile's exportAsynchronously(name:baseDir:exportFormat:callback:). I just did:

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)
jbm
  • 1,248
  • 10
  • 22