3 # pulseaudio_record_from_anything - record from all sources with pulseaudio
5 # Copyright (C) 2018 Antonio Ospite <ao2@ao2.it>
7 # This program is free software. It comes without any warranty, to
8 # the extent permitted by applicable law. You can redistribute it
9 # and/or modify it under the terms of the Do What The Fuck You Want
10 # To Public License, Version 2, as published by Sam Hocevar. See
11 # http://sam.zoy.org/wtfpl/COPYING for more details.
15 command -v /usr/bin/parec > /dev/null || { echo "parec missing, install pulseaudio-utils" 1>&2; exit 1; }
16 command -v /usr/bin/oggenc > /dev/null || { echo "oggenc missing, install vorbis-tools" 1>&2; exit 1; }
18 if pactl list short sinks | grep -q module-null-sink;
20 echo "The null sink is already loaded, bailing out." 1>&2
25 # It'll act as a "kitchen sink"... I'll show myself out.
26 PA_IDS=$(pactl load-module module-null-sink)
28 trap 'trap INT; for pa_id in $PA_IDS; do pactl unload-module "$pa_id"; done' EXIT
30 # Record from everything by redirecting any source to the null sink.
31 SOURCES=$(pactl list short sources | cut -f 2 | grep -v '^null\.monitor$')
32 for source in $SOURCES;
34 MODULE_ID=$(pactl load-module module-loopback latency_msec=1 source="$source" sink=null)
35 PA_IDS="$MODULE_ID $PA_IDS"
38 # Listen to what you are recording.
39 # NOTE: beware of Larsen effect when using microphones.
40 #pactl load-module module-loopback source=null.monitor sink=@DEFAULT_SINK@
43 pactl set-sink-mute null 0
46 parec -d null.monitor | oggenc -b 192 -o "recording_output_$(date +"%F_%T").ogg" --raw -