Realtime noise-removal with PulseAudio?

Solution 1:

Pulseaudio module module-echo-cancel

I started reading a lot about PulseAudio and "hidden" options it had so I could find one that was similar to this question. The one I found was the noise-cancellation module, which is one that dramatically lowers any static noise on the microphone and even A LOT of the background noise, basically giving you the benefit of only recording your own voice with excellent quality (For audio recording for example). To do this follow this steps:

  1. sudo nano /etc/pulse/default.pa

  2. Add the following line anywhere on the file, but I recommend almost at the end where you will find a comment about Echo Cancellation stuff (~line 140):

    load-module module-echo-cancel
    
  3. Reload PulseAudio (pulseaudio -k) or simply restart the computer. You should be able to select the new Noise Cancellation option from the Input Device Section:

    screenshot

You can find more information about it on the Echo Cancel Module Page

Set input as default

If you wish to set as default the echo cancel device simply turn the above line into:

load-module module-echo-cancel source_name=logitechsource

and then at the bottom of the file add

set-default-source logitechsource

In this case I named the source logitechsource, but you can name it whatever you want and simply either restart pulseaudio.

Rename device

Lastly, if you do not want a super long name on the Sound Settings (When you want to select an input/output device). My suggestion is renaming the input device like this:

load-module module-echo-cancel source_name=logitechsource source_properties=device.description=LogitechHD

And again, restarting pulseaudio. The end result looks like this:

screenshot

UPDATE - Full documentation Found Here Thanks to clément

Solution 2:

This is an old question, but I had the same problem and after some Googling (where I mostly found people who agreed it wasn't possible) and reading some man pages, I have now developed a solution based on user2330377's idea.

First you need to create a noise profile for SoX. Just use any audio recording program to record a few seconds of noise, then cd into the directory you saved it to and do sox noise.wav -n noiseprof noise.prof.

Then you need to create an ALSA loopback device:

sudo modprobe snd_aloop

This is required because pulseaudio, unlike Jack, cannot directly connect audio software together; we will hence use the loopback device as a proxy.

Now you need to start paman and find the names of both your microphone (or other recording device) and of the loopback device we just created. Once those are found, you can execute the following command to start recording sound from your microphone, piping it through SoX and then playing it on the loopback device:

pacat -r -d alsa_input.pci-0000_00_14.2.analog-stereo --latency=1msec|sox -b 16 -e signed -c 2 -r 44100 -t raw - -b 16 -e signed -c 2 -r 44100 -t raw - noisered noise.prof 0.2|pacat -p -d alsa_output.2.analog-stereo --latency=1msec

(Where you need to substitute the correct device names for the -d parameters -- the input device for the first pacat invocation and the loopback device output for the second.)

There you go, almost done! As a last step, start recording sound with the application of your choice, then start up pavucontrol, change to the "Recording" tab and set the audio device used for recording (displayed as the grey button to the right) to "Monitor of Loopback Audio Device". You should now have a clear and noise-free recording!