SoX Background Audio Monitoring – Triggered Recordings

SoX Background Audio Monitoring – Triggered Recordings

SoX offers quite a few ways to record audio. In this post, I’ll be covering how to record audio for the purposes of security. Home invasions are a sad fact of modern life for any number of reasons. I’ll show how to use SoX to capture audio so it can be added to the tools available to secure your personal belongings.

One of the most simplest ways to get a recording from a microphone is to use the following commands. I like to start out by listing all of my possible input devices. Then I bind my driver and device as the default input sources. This lets SoX do its work without complicated commands.

arecord -l
	card 2: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
export AUDIODRIVER=alsa
export AUDIODEV=hw:2,0
	from above, Card 2, Device 0
rec -c 1 "/home/local/Desktop/Audio Security/USBMic_1.wav" 

This is as simple as it gets. However we might not to want to let it run until we stop it. Since my audio input defualts are already set, all we need is the SoX record command.

rec -c 1 "/home/local/Desktop/Audio Security/USBMic_1_10Sec.wav" trim 0 10

In this next example, we’ll capture audio when a noise triggers it. Kris Occhipinti demonstrates that here, Youtube Clip.

rec -c 1 "/home/local/Desktop/Audio Security/USBMic_1_NoiseTriggered.wav" silence 1 0.1 5% 1 1.0 5%

Your command can run for a long time, but it will only capture audio once a noise threshold is reached. When the noise level drops below that threshold, the recording stops. This is useful to keep audio clips short without dead space.

In this next example, we will not stop the recording process when the threshold dips below our set value. This lets SoX record only noisy events and lets it continue to wait until another noisy event occurs before it continues to record. Here is the command for that.

rec -c 1 "/home/local/Desktop/Audio Security/USBMic_1_NoiseMonitoring.wav" silence 1 0.2 0.165% -1 0.2 0.165% 

The ability for a simple command like SoX to monitor your space can be useful when added to other security measures. Audio is a useful tool and there are many ways to enhance the results. I hope you have enjoyed this quick demonstration on how to use noise triggering for SoX. There are many more details behind the silence command used in SoX. I intentionally didn’t cover them here to keep this as simple as possible. Please feel at liberty to look up more about the silence command used in SoX on the SoX exchange documentation site,

Comments are closed.