如何用AVAudioEngine取消或删除回声/重复的声音?

我使用AVAudioEngine进行audiostream传输。 但是当我对麦克风说话的时候,它就像回声效果一样重复多次。 我想说话时,听起来只有一次,而不是多次。 我想取消回声或额外的噪音。

我怎样才能做到这一点?

var peerAudioEngine: AVAudioEngine = AVAudioEngine() var peerAudioPlayer: AVAudioPlayerNode = AVAudioPlayerNode() var peerInput: AVAudioInputNode? var peerInputFormat: AVAudioFormat? func setUpAVPlayer() { self.peerInput = self.peerAudioEngine.inputNode self.peerAudioEngine.attach(self.peerAudioPlayer) self.peerInputFormat = AVAudioFormat.init(commonFormat: .pcmFormatFloat32, sampleRate: 44100, channels: 1, interleaved: false) self.peerAudioEngine.connect(self.peerAudioPlayer, to: self.peerAudioEngine.mainMixerNode, format: self.peerInputFormat) print("\(#file) > \(#function) > peerInputFormat = \(self.peerInputFormat.debugDescription)") } 

我认为你应该能够通过这个代码来解决你的问题

 var reverbNode = AVAudioUnitReverb() reverbNode.loadFactoryPreset( AVAudioUnitReverbPreset.Cathedral) reverbNode.wetDryMix = 60 // Attach the audio effect node corresponding to the user selected effect peerAudioEngine.attachNode(reverbNode) 

另外,您也可以考虑采用其他方法,在您说话之后您可以将麦克风静音,并且在您的peerAudioEngine没有收到任何静音的inputaudio时必须手动检测。

这将彻底消除你的演讲回声。

欲了解更多信息,你可以访问http://asciiwwdc.com/2014/sessions/502