我正在尝试对音频应用一些效果后再保存。
我知道之前曾问过这个问题,所以我进行了搜索。但是,使用2 AVAudioPlayer
施加效果或保存之前请求播放所有音频文件时,以前的所有答案都在回答问题。
这是我的代码: 连接节点之前:
playerFile = try? AVAudioFile(forReading: audioFileURL!)
buffer = AVAudioPCMBuffer(pcmFormat: playerFile!.processingFormat, frameCapacity: AVAudioFrameCount(playerFile!.length))!
try! playerFile!.read(into: buffer!)
engine.attach(player!)
engine.attach(reverb)
engine.attach(distortion)
engine.attach(delay)
engine.attach(pitch)
engine.connect(player!, to: engine.mainMixerNode, format: buffer?.format)
player?.scheduleBuffer(buffer!, at: nil, options: [],
completionHandler: {
})
当我想播放具有特定效果的音频时,我将此功能称为:
func connect(audioUnits: [AVAudioUnit]) {
self.engine.disconnectNodeInput(self.engine.mainMixerNode)
for unitIndex in 0..<audioUnits.count{
if unitIndex == 0 {
engine.connect(player!, to: audioUnits[0], format: buffer?.format)
continue
}
engine.connect(audioUnits[unitIndex - 1], to: audioUnits[unitIndex], format: buffer?.format)
if unitIndex == (audioUnits.count - 1){
engine.connect(audioUnits[unitIndex], to: engine.mainMixerNode, format: buffer?.format)
player?.scheduleBuffer(buffer!, at: nil, options: AVAudioPlayerNodeBufferOptions.loops, completionHandler: nil)
engine.prepare()
try! engine.start()
player?.play()
}
}
}
一切正常,但是正如您所看到的,我与一个玩家合作,而不是更多。
那么,在添加效果后,是否可以找到一种方法来保存此音频文件,就像我添加效果一样(知道player
是AVAudioPlayerNode
)?