How to cancel or remove echo/repeated sound with AVAudioEngine?

人盡茶涼 提交于 2019-12-08 09:19:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!