Skip to content

**** ****

Public stash of coding, dj'ing and music stuff.

Automatic recording script for Raspberry PI box


Goal was to achieve automatic recording for anything that is fed to an external soundcard which gets it’s signal from mixer connected to all the audio source.

This was more like a 20 minute hackathon than coding contest.
There is need for separate cleanup script to wipe out all files older than 1 week after this has been proven to work

#!/bin/bash

pkill sox
function recordTheShit() {
rm -rf /opt/audio/placeholder.mp3
sox -d /opt/audio/placeholder.mp3 silence 1 5 4% 1 0:00:01 4%
wait

for i in /opt/audio/temp.mp3 ; do
   b=`stat -c %s "$i"`

if [ $b -ge 1000 ] ; then

NAME=`date +%Y-%m-%d_%H-%i-%S`
TIME=`date +%H:%i:%S`
FILENAME=/opt/shared/Recordings/$NAME.mp3
mv /opt/audio/placeholder.mp3 $FILENAME

mysql --host=localhost --user=rec --password=rec recordings << EOF
INSERT INTO recordings (time,filename) VALUES ('$TIME','$FILENAME');
EOF
fi
rm -f /opt/audio/placeholder.mp3

done

recordTheShit 
}
recordTheShit 



Categorized as: Uncategorized rant



Leave a Reply

Your email address will not be published. Required fields are marked *