很简单,应该可以看懂吧
private var engine: AVAudioEngine?
extension PithyisCool {
private func startEarReturn() {
engine = AVAudioEngine()
guard let engine = engine else { return }
let playNode = AVAudioPlayerNode()
engine.attach(playNode)
let input = engine.inputNode
let output = engine.outputNode
engine.connect(input,to: output,format: input.inputFormat(forBus: 0))
engine.prepare()
do {
try engine.start()
} catch {
}
}
private func stopEarReturn() {
engine?.stop()
engine?.inputNode.removeTap(onBus: 0)
engine = nil
}
}