RIP Sound Card Audio in Linux

Sometimes you need a quick and dirty way of ripping the audio of your sound card, in Linux you can easily do it with the following script:


#!/bin/bash
set -x
WAV="$1"
if [ -z "$WAV" ]; then
    echo "Usage: $0 OUTPUT.WAV" >&2
    exit 1
fi
rm -f "$WAV"

# Get sink monitor:
MONITOR=$(pactl list | egrep -A2 '^(\*\*\* )?Source #' | \
    grep 'Name: .*\.monitor$' | awk '{print $NF}' | tail -n1)
echo "set-source-mute ${MONITOR} false" | pacmd >/dev/null

# Record it raw, and convert to a wav
echo "Recording to $WAV ..."
echo "Close this window to stop"
parec -d "$MONITOR" | sox -t raw -b 16 -e signed -c 2 -r 44100 - "$WAV"

 
Store it somewhere in your PATH, and when you need to record the audio just use it as:


./soundRipper.sh output.wav

 
If you don’t want to store wave files you can convert it as shown HERE

Sources:

https://outflux.net/blog/archives/2009/04/19/recording-from-pulseaudio/
https://www.pantz.org/software/alsa/recording_sound_from_your_web_browser_using_linux.html