Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a 24/7 audio stream on a Linux server for which I need a silence detector to let me know (via email) when the stream is down.
Something similar to http://www.pira.cz/eng/silence.htm, although I donīt need that many features.
The easiest would probably be a bash script that using someting like sox? arecord? to trigger the email alert.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
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.
<br />
<b>Warning</b>: require_once(/home/jlinkels/public_html/links/../../library/application_top.inc.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in <b>/home/jlinkels/public_html/links/CheckLine.php</b> on line <b>2</b><br />
<br />
<b>Fatal error</b>: require_once() [<a href='function.require'>function.require</a>]: Failed opening required '/home/jlinkels/public_html/links/../../library/application_top.inc.php' (include_path='.:/usr/share/php:/usr/share/pear') in <b>/home/jlinkels/public_html/links/CheckLine.php</b> on line <b>2</b><br />
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
For the loop containing the sound detection you don't need any of the functions in the include file. I posted an example from which you can develop your application, not a complete program.
I'm trying to do the same thing. Detecting silence in a broadcast. I'm not familiar with arecord but I don't mind trying it out. My question is how to detect the silence? Could anyone be a bit more of a help in that? Or direct me in the right direction at least?
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
If you use arecord with 8-bit unsigned output, it will produce a stream of values where 0 is the maximum negative peak of the sinus, 255 the maximum positive peak, and 127 the zero crossing. So if you detect 127 +/- 5 counts you have silence. The +/- is a bit dependent on you audio card, if it is noise you might want to increase that window.
I guess the biggest question is, do I need a sound-card? I'm looking at a stream and need to see if there's silence in the stream. I know I might have to record the stream, 10 seconds or so and then have arecord or something else look into it to check for silence, but does that require sound-card?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.