I need to monitor my audio line-in in linux, and in the event that audio is played, the sound must be recorded and saved to a file. Similiar to how motion monitors the video feed.
Is it possible to do this with bash? something along the lines of:
#!/bin/bash
# audio device
device=/dev/audio-line-in
# below this threshold audio will not be recorded.
noise_threshold=10
# folder where recordings are stored
storage_folder=~/recordings
# run indefenitly, until Ctrl-C is pressed
while true; do
# noise_level() represents a function to determine
# the noise level from device
if noise_level( $device ) > $noise_threshold; then
# stream from device to file, can be encoded to mp3 later.
cat $device > $storage_folder/$(date +%FT%T).raw
fi;
done;
EDIT: The flow I'd like to get from this program is
a. when noise > threshole, start recording
b. stop recording when noise < threshold for 10 seconds
c. save recorded piece to seperate file
Thank you
Stefan