0

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)") 
}
rmaddy
  • 298,130
  • 40
  • 468
  • 517
Saurabh Jain
  • 1,660
  • 10
  • 28

1 Answers1

-2

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

Paras Gorasiya
  • 1,131
  • 2
  • 12
  • 30