Hardware Reference
In-Depth Information
while true ; do
NOISE=$(sox -t alsa plughw:1 -n stat trim 0 00:00:01 2>&1 > /dev/
null | grep 'Maximum amplitude' | cut -d ':' -f 2 | tr -d ' ')
if noise_compare $NOISE $THRESHOLD; then
echo "Noise detected ($NOISE) - Recording..."
sox -t alsa plughw:1 $(date +%Y%m%d-%H%M%S).wav trim 0 00:05:00
fi
done
The THRESHOLD variable holds, of course, the threshold amplitude value that you
found out by calibrating your microphone. Next comes the noise_compare function.
A function is a piece of code that can be called from other places in a script. In this
case, we use it to compare two floating point numbers by passing them to the awk
command since bash doesn't have this ability built-in.
Then we enter an infinite loop, which means our script will continue to run until
we press Ctrl + C to break out of the loop. Next, we chain together a series of
commands to extract the Maximum amplitude value from sox and store it in the
NOISE variable, which is then compared with our THRESHOLD variable with the help
of the noise_compare function.
If the NOISE value is larger than the THRESHOLD value, we start a 5-minute recording
with the current date and time as the filename.
Now that you know how to do sound detection, you can easily swap out the sox
recording command to play an alarm bell or send an e-mail warning about a possible
noisy intruder as described in the Sending e-mail updates section of Chapter 5 , Taking
your Pi Off-road .
Calling your fellow agents
When you're out in the field and need to call in a favor from a fellow agent or report
back to HQ, you don't want to depend on the public phone network if you can avoid
it. Landlines and cell phones alike can be tapped by all sorts of shady characters and to
add insult to injury, you have to pay good money for this service. We can do better.
Welcome to the wonderful world of Voice over IP ( VoIP ). VoIP is a blanket term
for any technology capable of delivering speech between two end users over IP
networks. There are plenty of services and protocols out there that try to meet this
demand, most of which force you to connect through a central server that you don't
own or control.
 
Search WWH ::




Custom Search