我正在尝试使用AKNodeRecorder在我的应用程序中记录AudioKit播放的音乐的输出。但是,它似乎正在录制,然后每当录制停止时,当我尝试播放最近录制的文件时,该文件显示为空,因此无法播放。这是使用此模块的所有代码段
var recorder: AKNodeRecorder!
var player: AKAudioPlayer!
func setupSound() {
var tape: AKAudioFile!
var oscilator = AKOscillator(waveform: AKTable(.sawtooth))
let oscMixer = AKMixer(oscilator)
do {
tape = try AKAudioFile()
player = try AKAudioPlayer(file: tape)
AudioKit.output = oscMixer
try AudioKit.start()
recorder = try AKNodeRecorder(node: oscMixer, file: tape)
} catch {
print("Error in setup: \(error)")
}
}
@IBAction func startRecord(_ sender: Any) {
if !recorder.isRecording {
do {
try recorder.reset()
try recorder.record()
} catch {
print("Error in start of record: \(error)")
}
toggleEnable(extraButton: playRecordButton, enableButton: false)
self.recordButton.setTitle("Stop Recording", for: .normal)
}
else {
recorder.stop()
toggleEnable(extraButton: playRecordButton, enableButton: true)
self.recordButton.setTitle("Record", for: .normal)
}
}
@IBAction func playRecord(_ sender: Any) {
if !player.isPlaying {
player.play()
playRecordButton.setTitle("Pause Record", for: .normal)
toggleEnable(extraButton: recordButton, enableButton: false)
}
else {
do {
try player.reloadFile()
} catch {
print("Error in reloading of file \(error)")
}
player.stop()
playRecordButton.setTitle("Play Record", for: .normal)
toggleEnable(extraButton: recordButton, enableButton: true)
}
}