Skip to content

Instantly share code, notes, and snippets.

@Zverik
Created September 17, 2014 19:41
Show Gist options
  • Save Zverik/16ff6e8e4ebf5fe62da4 to your computer and use it in GitHub Desktop.
Save Zverik/16ff6e8e4ebf5fe62da4 to your computer and use it in GitHub Desktop.
PulseAudio setup for recording osm radio from skype and mic
#!/usr/bin/sh
# PulseAudio setup for recording osm radio from skype and mic
function rec_start() {
IP=127.0.0.1
PASSWORD=password
DATE=$(date +%y%m%d-%H%M)
# Initializing microphone
MIC_ID=$(pactl list short sources|grep GoMic|grep input|cut -f 1)
if [ -z "$MIC_ID" ]; then
echo Please plug in Samson Go Mic
exit 1
fi
MIC=$(pactl list short sources|grep GoMic|grep input|cut -f 2)
# Selecting sound card
CARD_ID=$(pactl list short sinks|grep C-Media|cut -f 1)
if [ -n "$CARD_ID" ]; then
CARD=$(pactl list short sinks|grep C-Media|cut -f 2)
else
CARD_ID=$(pactl list short sinks|grep 00_1b|cut -f 1)
CARD=$(pactl list short sinks|grep 00_1b|cut -f 2)
echo No USB sound card found, using $CARD
fi
# Initializing virtual sinks
echo Starting null sink mic+music
SINK_MM=$(pactl load-module module-null-sink sink_name=mic_music sink_properties=device.description="mic+music")
echo Starting null sink for skype
SINK_SKYPE=$(pactl load-module module-null-sink sink_name=skypep sink_properties=device.description="skype-proxy")
echo Starting null sink recording
SINK_REC=$(pactl load-module module-null-sink sink_name=recording sink_properties=device.description="recording")
if [[ -z "$SINK_MM" || -z "$SINK_SKYPE" || -z "$SINK_REC" ]]; then
echo Failed to start one of the sinks
pactl unload-module module-null-sink
exit 1
fi
# Tying sinks with loopbacks
echo Loopback mic → mic+music
LOOP1=$(pactl load-module module-loopback source=$MIC sink=mic_music)
echo Loopback mic+music → recording
LOOP2=$(pactl load-module module-loopback source=mic_music.monitor sink=recording)
echo Loopback skype → recording
LOOP3=$(pactl load-module module-loopback source=skypep.monitor sink=recording)
echo Loopback recording → sound card
LOOP4=$(pactl load-module module-loopback source=recording.monitor sink=$CARD)
echo Starting 3 gstreamers for date $DATE
gst-launch-0.10 pulsesrc device=$MIC ! audioconvert ! audio/x-raw-int,channels=1 ! lamemp3enc bitrate=96 cbr=true ! filesink location=mic-$DATE.mp3 &
gst-launch-0.10 pulsesrc device=skypep.monitor ! audioconvert ! audio/x-raw-int,channels=1 ! lamemp3enc bitrate=96 cbr=true ! filesink location=skype-$DATE.mp3 &
gst-launch-0.10 pulsesrc device=recording.monitor ! audioconvert ! audio/x-raw-int,channels=1 ! lamemp3enc bitrate=64 cbr=true ! tee name=t ! queue ! shout2send ip=$IP port=8000 password=$PASSWORD mount=osmru 'streamname=Radio OSM Rus' t. ! queue ! filesink location=osmru-$DATE.mp3 &
}
function rec_stop() {
pkill gst-launch
pactl unload-module module-loopback
pactl unload-module module-null-sink
}
function pamove() {
if [ "$2" -eq "→" ]; then
WHAT=sink-input
else
WHAT=source-output
fi
CLIENT_ID=$(pactl list short clients|grep -i $1|cut -f 1)
if [ -n "$CLIENT_ID" ]; then
SINK_ID=$(pactl list short ${WHAT}s|grep $CLIENT_ID|cut -f 1)
if [ -n $SINK_ID ]; then
pactl move-$WHAT $SINK_ID $3
return 0
fi
fi
echo Client $1 has no $WHAT
}
function fix_outputs() {
pamove vlc → mic_music
pamove skype → skypep
pamove skype ← mic_music.monitor
}
case $1 in
start) rec_start ;;
stop) rec_stop ;;
fix) fix_outputs ;;
*)
echo "Usage: $0 start — load modules and start recording"
echo " $0 fix — set skype and vlc outputs to proper sinks"
echo " $0 stop — unload gstreamer and modules"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment