Skip to content

Instantly share code, notes, and snippets.

@edulix
Last active October 26, 2015 09:13
Show Gist options
  • Select an option

  • Save edulix/4908a653b4bb104a9bcb to your computer and use it in GitHub Desktop.

Select an option

Save edulix/4908a653b4bb104a9bcb to your computer and use it in GitHub Desktop.
#!/bin/bash
# The MIT License (MIT)
#
# Copyright (c) 2015 Eduardo Robles Elvira <edulix AT agoravoting DOT com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
SAVE_PATH="/home/$(whoami)/multimedia/recordings/"
[ -d ${SAVE_PATH} ] || mkdir -p ${SAVE_PATH}
DATE=$(date +%Y-%m-%d_%H:%M:%S)
echo "name = '$1'"
if [ ${#1} -eq 0 ]
then
echo "try: $0 <name>"
exit 1
fi
FILEPATH="${SAVE_PATH}/recording_$1_$DATE.mp3"
echo -e "Recording to $FILEPATH\n\n"
pactl unload-module module-loopback
pactl unload-module module-null-sink
SINK_ID=$(pactl load-module module-null-sink sink_name='io-recorder')
ALSA_INPUT=$(pacmd list | grep alsa_input | grep "Default source name: " | sed 's/Default source name: //g' -)
echo "ALSA input: $ALSA_INPUT"
ALSA_OUTPUT=$(pacmd list | grep alsa_output | grep "Default sink name: " | sed 's/Default sink name: //g' -)
echo "ALSA output: $ALSA_OUTPUT"
LOOP1_ID=$(pactl load-module module-loopback source=$ALSA_INPUT sink='io-recorder')
LOOP2_ID=$(pactl load-module module-loopback source="$ALSA_OUTPUT.monitor" sink='io-recorder')
parec -d 'io-recorder.monitor' | sox -t raw -r 44100 -b 16 -L -e signed -c 2 - -C192 $FILEPATH
pactl unload-module module-loopback
pactl unload-module module-null-sink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment