Hello … hello … hello!

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: /downloads/pulseaudio/aec/call-no-aec (or download ogg, aac)

With AEC: /downloads/pulseaudio/aec/call-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.

26 Comments

Add yours

  1. Nice stuff! Glad to see that this works its way into Pulseaudio, so that all applications will benefit.

  2. EdgeWiseInAnnArbor

    August 25, 2011 — 7:32 pm

    So, could I use this to have a combination of baby monitor and white noise generator? Right when I listen to our baby monitor receiver, I mostly hear the white noise generator in the room.

    • Presumably you could do this with standard tools in Linux. Unless I misunderstand what you need, you’re problem isn’t related to echo-cancellation.

  3. This is really nice work. Can’t wait to get advantage form this in Empathy for SIP calls. :-)

  4. The release of this feature makes me deeply pleased. Good work chaps.

  5. Great Work Arun,

    Is there a noise cancellation in pulseaudio also? because recording using mic, catches too much fan noise, clicks etc., in Linux.

    Hope to see noise cancellation in pulseaudio.

    Thanks.

    • Hey Asif — as I mentioned the Speex preprocessing bits also include noise suppression, and I’ve seen this be quite helpful with fan noise. Clicks, on the other hand, might either be your system not being able to keep up, or driver bugs.

  6. I want to record Hindi pronunciations at forvo.com, but with Flashplugin and Microphone there is a constant ‘static’ noise.

    That noise is not there in any other sound applications, arecord, sound-recorder, empathy, skype, etc.

    Please see these 2 audio clips (2.5 seconds each) http://www.forvo.com/word/mukherjee/#hi

    In the second recording (mine), there is a noise with flashplugin.

    The same ‘trrrrrr’ noise is not there in windows.

    Is there a solution? The opensource gnash and lightspark do not have mic support when I used them.

  7. Hi Arun, I tried the WebRTC test programs recently. Echo cancellation does not work if using different devices for playback and capture ( a USB microphone for example). What is your experience with it?

  8. Hi Arun,

    Just in case, you didn’t try adopting WebRTC echo cancelation to frame sizes other than 10ms, did you? (They require frame sizes to be 10ms, but I need 48ms.)

  9. Hi, I am trying to use this module for my social robot. The problem is that the robot has buil-in its body the microphone which is used to Automatic Speech recognition, but the robot voice is collected for the microphone too. I want to substract its own voice of the signal received for the built-in microphone, because if not substract this signal the ASR give me misunderstandings.

    If the user doesn’t talk but the robot is speaking I want to received a silence signal… but if users start to talk (even at the same time that the robot) I want only received the user voice. Previously I used a wireless headset microphone to avoid the robot voice signal but it is more handy and natural to use a built-into microphone.

    Do you believe that this echo-cancel module is suitable for me purpose?

    Thanks!

    • Sounds like the echo-cancel module should suit your purpose. The current RCs have significant improvements in the quality of echo cancellation so you might want to try that out.

      • mmm RC’s? the new algorithms implemented in Pulseaudio 1.1? I spend all day “fighting” with Pulseaudio 1.1 in Ubuntu 10.10 (by default is installed Pulseadio 0.9, and it hasn’t echo cancellation). But really I still have some problems… I have many sound cards devices connected to the laptop, in ALSA always start them in the right order (by /etc/modprobe.d/alsa-base.conf), but in Pulseaudio some times, some sound cards are not detected, and in the other hand, the another problem is that I write in /etc/pulse/default.pa the module-echo-cancelation for loading it… but the module is not loaded… I need to write in a terminal the instruction later have been started Ubuntu. I guess the problem is that Pulseaudio 1.1 is not the default of Ubuntu 10.10.

  10. Hi Arun,

    I downloaded and converted call-no-aec.oga to wav format. Should I notice echo cancellation if I play this audio file with module-echo-cancel loaded with appropriate sink and source?

  11. Hi Fahad, this isn’t how echo cancellation works. If you play a wav or ogg or mp3 file that exhibits a recorded echo, it will just play back that stream, echo and all.

    The echo cancellation module is meant to work with the hardware combination of speaker and mic.

  12. i’m implementing a voip application using gstreamer, i use the example of the rtp in the plugin-good! i want to implement echo cancellation, i couldn’t use the speex echo canceller with gstreamer because the input and the output are not in the same process. So, i want to use pulse audio to make echo cancellation? would you help me how to deal with? thanks

Leave a Reply to Fernando Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.