In the past I posted a few tips and scripts for doing voice operated audio recording (VOX) under Linux. I’ve done more research on this over time and now have what I believe to be a more refined version as well as finally figured out how to make a timed script with the help of folks from LinuxQuestions.org.
#!/bin/bash
read -p "How many seconds to run? ==> " count_secs
if [[ $count_secs -gt 0 ]]
then
rec -r 22050 -c 1 -p | sox -p OUTPUT.mp3 silence 1 0.1 1% -1 0.5 1% &
my_PID=$!
sleep $count_secs
kill -15 $my_PID
fi
When you run the above script it will ask you to input the total recording time in seconds, then end itself when that time expires. I’ve hard coded the sox command to output a 22 kHz, mono, 32 kbps MP3 file. There are still many many ways to modify and improve this script, but this is working for my needs now.
I’ve also learned a lot more about how to use the “silence” option in sox thanks to this blog post which I suggest you read to understand how to tweak the parameters. The way I hardcoded the volume thresholds and silence detection time works well to my ear as far as cutting silence from scanner radio traffic. YMMV.
I have one other revised script which first uses arecord and then sends the output to sox for trimming. The method below has an advantage in that you can more finely tweak the initial capture parameters. The disadvantage to this method is that there is a second separate processing step with sox, instead of doing it all in one shot as in the first script.
#!/bin/bash
#USAGE: ./sox_vox_recorder.sh xxx output.mp3
#USAGE: Records from line-in for xxx seconds to output.mp3, then detects and trims silence
TIME=$1
OUTPUT=$2
arecord -f S16_LE -c1 -r22050 -t raw -d ${TIME} | lame -r -s 22.05 -m m -b 64 - ${OUTPUT} ;
sleep 1 ;
sox ${OUTPUT} ${OUTPUT}_processed.mp3 silence 1 0.1 1% -1 0.5 1% ;
I can see lots of tweaks to both of these scripts, such as capturing with OGG, or making a case-selection menu to choose capture parameters, and so forth. Maybe I’ll play with this in the future.