This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
ubuntu:pluseaudio [2019/01/11 10:20] tschulz |
ubuntu:pluseaudio [2019/01/11 10:27] tschulz [Noise Reduction Script] |
||
---|---|---|---|
Line 37: | Line 37: | ||
load-module module-esound-protocol-tcp auth-anonymous=1 | load-module module-esound-protocol-tcp auth-anonymous=1 | ||
</file> | </file> | ||
+ | |||
+ | ===== Noise Reduction Script ===== | ||
+ | <file bash> | ||
+ | #!/bin/bash | ||
+ | time=5 | ||
+ | workDir='/tmp' | ||
+ | record() | ||
+ | { | ||
+ | echo "Recording background noise. Keep quiet for $time seconds." | ||
+ | sleep 3 | ||
+ | arecord -f cd noise.wav & | ||
+ | PID=$! | ||
+ | sleep $time | ||
+ | kill $PID | ||
+ | aplay noise.wav | ||
+ | } | ||
+ | |||
+ | #get pulse audio devices | ||
+ | devices=`pactl list | grep -E -A2 '(Source|Sink) #' | grep 'Name: ' | grep -v monitor | cut -d" " -f2` | ||
+ | if [ `echo "$devices" | grep -c aloop` -lt 1 ]; then | ||
+ | echo "No loopback device created. Run 'sudo modprobe snd_aloop' first." | ||
+ | exit | ||
+ | fi | ||
+ | |||
+ | cd $workDir | ||
+ | |||
+ | #record noise sample | ||
+ | record | ||
+ | while true; do | ||
+ | read -p "Do you wish to re-record the noise sample?" yn | ||
+ | case $yn in | ||
+ | [Yy]* ) record;; | ||
+ | [Nn]* ) break;; | ||
+ | * ) echo "Please answer yes or no.";; | ||
+ | esac | ||
+ | done | ||
+ | |||
+ | #create noise profile | ||
+ | sox noise.wav -n noiseprof noise.prof | ||
+ | |||
+ | input=`echo "$devices" | grep input.*pci` | ||
+ | output=`echo "$devices" | grep output | grep 1b` | ||
+ | |||
+ | echo "Sending output to loopback device. Change recording port to <Loopback Analog Stereo Monitor> in PulseAudio to apply. Ctrl+C to terminate." | ||
+ | |||
+ | #filter audio from $input to $output | ||
+ | pacat -r -d $input --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 $output --latency=1msec | ||
+ | </file> | ||
+ |