#!/bin/bash # Simple script to record ambient sounds. recording is paused # until a sound threshold is reached and stopped after 5 seconds # of silence. Sound clip is saved as flac,date/time stamped and # the process repeated until a specified time duration. # NOTE: sox is set to use the default audio input. If using pulseadio, # especially with KDE and USB microphone, use # 'pulse audio volume control' and mixer to set the correct input source. # DEPS: # bash # bc # sox # flac # alsa START_REC=$SECONDS AUDIO_PATH=${AUDIO_PATH:-/$HOME/audio} mkdir -p $AUDIO_PATH # trap ctrl-c and call ctrl_c() trap ctrl_c INT function ctrl_c() { echo "terminating script..." exit 0 } # Check if ran with root permissions if [ `id -u` -eq 0 ]; then echo "This script must not be run as root!" exit 1 fi if [ -n "$1" ]; then REC_LEN=$(echo "scale=0; ($1*3600)/1" | bc) echo "Recording for $1 hours ($REC_LEN seconds)." else echo "Usage: $0 hours" echo "Specify the number of hours script to to run." echo "Fractional values are allowed." exit 1 fi while [ $(($SECONDS - $START_REC)) -lt $REC_LEN ]; do /usr/bin/rec -S -c 1 -b 16 -r 32000 $AUDIO_PATH/sleep.flac silence 1 0.1 3% 1 5.0 3% DATE=$(date +%Y%m%d%H%M%S) mv $AUDIO_PATH/sleep.flac $AUDIO_PATH/$DATE-sleep.flac done echo "Time expired."