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

1

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)") 
}
Velour answered 7/8, 2017 at 2:57 Comment(8)
Please show us some code about what have you done so far.Cheremkhovo
@ParasGorasiya Please check my codeVelour
Are you recording something in an environment that creates echo?Cheremkhovo
@ParasGorasiya Yes, I am recording using AVaudioEngine but when I send it and play it creates echo or repeating voiceVelour
I meant are your recording in an empty big room which would create echo while recording? So that might be the actual issue.Cheremkhovo
no.. echo create every time by default. Is there any property to cancel the echo?@ParasGorasiyaVelour
Did you fix this?Summation
@VladimirPrigarin Yes, but currently i am not workingVelour
C
-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

Cheremkhovo answered 7/8, 2017 at 4:47 Comment(1)
Have you any other solution?Velour

© 2022 - 2024 — McMap. All rights reserved.