Linux语音通话如何消除回声(PulseAudio)

原文链接:http://arunraghavan.net/2011/08/hello-hello-hello/

原作者:Arun Raghavan

注意:此方法处于试验阶段,现阶段基于speex,之后有可能使用webrtc-audio-processing。webrtc-audio-processing 现在处于开发阶段,没文档没sample。


I have a secret to confess. I’ve spent a great deal of time over the last few months talking to myself. I can’t say I haven’t enjoyed it — it turns out my capacity to entertain myself is far greater than initially suspected. But I hear you ask … why?

Here at Collabora, I’ve been building on Wim’s previous work on adding echo cancellation to PulseAudio. Thanks go to Intel for supporting us in continuing this work. Before too long, all this work will be trickling down to your favourite Linux distribution and all your friends will stop hating you.

First, a quick recap on what acoustic echo cancellation (AEC) is. If you already know this, you might want to skip this paragraph and the next. Say you’re on your laptop, and you receive a voice call from your friend. You don’t have a pair of headphones lying around, so you’re just going to use your laptop’s built-in speakers and mic. When your friend speaks, what she says is played out the speakers, but is also captured by the microphone and she gets to hear herself speak, albeit a short while (a few hundred milliseconds or more) later. This is called acoustic echo, and can be frustrating enough to make conversation nigh impossible. There are other types of echo for phone systems, but that’s not interesting to us at the moment.

This problem is common on pretty much all devices that you use to make phone calls. Astute readers will ask why they don’t actually face this problem on their phone. That’s because your phone (or, if you have a cheap phone, your phone company) has special software hidden away that removes the echo before sending your signal along to the other end. On laptops, which are general-purpose hardware, the job of echo cancellation is left to either your operating system (Windows XP onwards, for example) or your chat client (Skype, for example) to provide.

On Linux, we implement echo cancellation as a PulseAudio module (code-ninja Wim Taymans wrote this last year). We use the Speex DSP library to perform the actual echo cancellation. The code’s quite modular, so it’s not very hard to plug in alternate echo cancellers (we even include an alternate implementation, which isn’t quite as effective as Speex).

Recently, we plugged in some more bits from the Speex library to do noise suppression and digital gain control (so you can quit twiddling with your mic volume for the other end to be able to hear you). We also added a bunch of fixes to reduce CPU consumption significantly — this should be good enough to run on a netbook and reasonably recent ARM platforms.

While all this sounds nice, I think a demo would sound (haha!) nicer …

Without AEC:

(or download  ogg aac )

With AEC:

(or download  ogg aac )

This is a recording of a call between my laptop and N900. The laptop is playing audio out the speakers and recording with the built-in mic. What you hear is the conversation as heard on the N900.

All this echo cancelling goodness will come to a Linux distribution near you in the upcoming 1.0 release of PulseAudio. The next version of the GNOME IM client, Empathy (3.2), will actually make use of this functionality. In due time, we intend to make it so that all voice applications will end up using this functionality (so if you’re writing a VoIP application and don’t want to use this functionality, you need to set a special stream property to disable this —filter.suppress="echo-cancel").

For the impatient among you, you can try all this out by getting recent testing versions of PulseAudio (I know packages are available for Ubuntu, Debian, Gentoo and Mageia at least). To force your phone streams to use echo cancellation, just run pactl load-module module-echo-cancel, and you’re done.

There’s still some work to be done, refining quality and using other AEC implementations (in the short-term, the WebRTC one looks promising). Things don’t work at all if you’re using different devices for playback and capture (e.g. laptop speakers and webcam mic). These are things that will be addressed in coming weeks and months.

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

弄了一天终于知道怎么弄了。。。真是丫了个蛋疼。。。

1. 首先需要安装speex,这一步我不确定是不是必须的,但Pulse Audio的作者说要安装那就安吧;

2. 执行pactl load-module module-echo-cancel aec_method=\"speex\",这是参照manal写的;

3. 最坑爹的来了,下面的代码片段在注释所示的链接找的,而且Pulse Audio作者也说要这么做。不过事实上,除了在pactl list中的确能看到加载了echo-cancel模块作为filter外,什么实际效果都没。而且在pacmd中输入list-modules发现echo-cancel的use是0。

// see how-to-use-echo-cancellation-module-in-pulseaudio[http://stackoverflow.com/questions/13363241/how-to-use-echo-cancellation-module-in-pulseaudio]
setenv("PULSE_PROP", "filter.want=echo-cancel", 1);
解决办法是打开pavucontrol,在Playback和Recording选项卡中手动选择对应程序的声音来源为×××echo-cancle×××,关闭窗口后,你的设置会被保存。这里还有个问题,就是到底要为输入还是输出加载回声消除模块。Arch的文档说只需要给录音加载模块就好,如下

不过吧,经过我在Ubuntu上反复测试,只开任何一个,都没任何效果。当两个都开时,喇叭出来的声音在录音中几乎听不到;

4. 最后,做完这些,要把音量开大点,加载了echo-cancel模块的输出的音量会减小许多,而且声音将明显失真,不过作为语言聊天完全足够了。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值