Ive been trying to implement the AVFoundation's framework AVFAudio in order to record audio, play audio, as well as change the audio data per the user's selected presets. Ive also been trying to find out how to save files locally to the user's device, however, upon reading apple's documentation on AVFAudio, I can hardly make any sense of which steps to take when creating these files. Ive been following along with https://www.raywenderlich.com/21868250-audio-with-avfoundation/lessons/1 and managed to set up some functions here.
Here I have set up saving the audio, but as you can see, this would only save the audio to a temporary directory. I am wondering how I can save the audio file locally to the user's device.
// MARK: Saving audio
var urlForVocals: URL {
let fileManger = FileManager.default
let tempDirectory = fileManger.temporaryDirectory
let filePath = "TempVocalRecording.caf"
return tempDirectory.appendingPathComponent(filePath)
}
I am generally confused about the AVFoundation's framework when using AVFAudio and the documentation https://developer.apple.com/documentation/avfaudio does not go into specifics of how to implement each method. For Example; The Doc states that for Creating an Audio Player: We need to init(contentsOf:url), but does not go into what the url is and why we are using it? Can anyone help me understand what steps to take further, I feel like i'm running around in circles trying to understand this framework and the apple documentation.