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

标签 ios swift avaudioengine avaudioplayernode

我正在使用 AVAudioEngine 进行音频流。但是当我对着麦克风说出任何一个词时,它会重复多次,就像回声效果一样。我希望当我说话时,听起来只有一次,而不是多次。我想消除回声或额外的噪音。

我怎样才能做到这一点?

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 未收到任何输入音频时必须手动检测您将其静音。

这将完全消除语音中的回声。

更多信息请访问 http://asciiwwdc.com/2014/sessions/502

关于ios - 如何使用 AVAudioEngine 取消或删除回声/重复声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45538806/

相关文章:

c++ - Three.js 移植到原生代码?

ios - 使用 RealmSwift 将 Realm 对象与 iOS 9 中的 UITabBarController 相关联

string - 在 Swift 中,如何检查对象 (AnyObject) 是否为字符串?

ios - 解析 Swift 自定义对象 ID?

ios - 将单声道音频数据传递给 AVAudioEnvironmentNode

ios - 在 TableView 中显示文本

iphone - 从另一个类更改 UILabel 的文本

android - 检测桌面或设备上播放的内容?

audio - 如何从iPhone 11或iPhone 11 Pro Max获得采样率为44100的音频

swift - 计时问题: Metronome using AVAudioEngine scheduleBuffer's completion handler