问题
I am using the AVAudioEngine for audio streaming. But when I speak any word into the mic, it repeats multiple times, just like echo effect. I want when I speak, it sounds only one time, not multiple times. I want to cancel the echo or extra noise.
How can I achieve this?
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)")
}
回答1:
I think you should be able to solve your issue by this code
var reverbNode = AVAudioUnitReverb()
reverbNode.loadFactoryPreset( AVAudioUnitReverbPreset.Cathedral)
reverbNode.wetDryMix = 60
// Attach the audio effect node corresponding to the user selected effect
peerAudioEngine.attachNode(reverbNode)
Also you may want to consider other approach in which you can mute your mic after you speak and that you have to detect manually when your peerAudioEngine
doesnt receive any input audio you mute it.
This will completely eliminates echo from your speech.
For more info you can visit http://asciiwwdc.com/2014/sessions/502
来源:https://stackoverflow.com/questions/45538806/how-to-cancel-or-remove-echo-repeated-sound-with-avaudioengine