The principle is extremely simple, but the implementation is a bit more difficult.
arecord is the correct choice. Bash is difficult because you have to regard hex values. Then you have to build a certain timeout because you don't want to be alerted for a 2 seconds silence.
This is how I did it:
From a php parent program I issue the command with an exec function:
arecord | silent_detect.php
In the silent_detect.php I read from stdin and look if there is silence. If there is silence, I wait the timeout time. If there is no sound during the timeout an alarm is generated. I have put that program here:
http://mail.linkels.net/~jlinkels/links/CheckLine.php. It was only modified by me, not written. The code is not that beautiful. Note that I immediately write the input to stdout before checking on the contents, but that is because I pipe that into a recording program for archiving purposes. If arecord is called without parameters it produces 8-bit unsigned, 0x80 is zero therefor. Be sure to call arecord with the correct audiodevice and use amixer to make sure capture is
on on the channel and volume is 100%. Do
not let the stream playback which is captured.
The next problem occurs when you want to stop both arecord and the silent detection. Either you need to fork the exec from your parent program or you need to record the pids of these programs.
Believe it or not, I am monitoring AND recording 4 independent audio streams for a radio station, AND perform playback of 4 independent streams on a Celeron 600 computer.
jlinkels