Reputation: 1466
I am trying to achieve the ability to record something (microphone or oscillator or any other input), I need it to be as accurate as it could be in terms of executing a callback right after recording finishes, so I thought ClipRecorder could help me here. this piece of code goes into a simple view controller's viewDidLoad
function, and the code executed and get to the end but the callback of the clip recorder never executed.
Can you please advise me what did I do wrong? I am very new to AudioKit so it could be my miss-understanding of things. here is the code:
AKSettings.bufferLength = .shortest
AKSettings.defaultToSpeaker = true
try! AKSettings.setSession(category: .playAndRecord)
let oscillator = AKOscillator()
let oscMixer = AKMixer(oscillator)
AudioKit.output = oscMixer
AudioKit.start()
oscillator.start()
let clipRecorder = AKClipRecorder(node: oscMixer)
do{
AKLog("1")
try clipRecorder.recordClip(time: 0, duration: 2, tap: nil, completion: { url, something, err in
AKLog("recorded clip")
oscillator.stop()
})
AKLog("2")
} catch let error as ClipRecordingError {
print("\(String(describing: error.errorDescription))")
} catch {
print("something general")
}
logs 1,2 are printed, 'recorded clip' is not printed.
many thanks!
Upvotes: 2
Views: 350