LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Audio Silence Detection (https://www.linuxquestions.org/questions/linux-general-1/audio-silence-detection-914902/)

ctkroeker 11-22-2011 08:23 AM

Audio Silence Detection
 
Hi,

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.

Can you help me? Thanks!

jlinkels 11-23-2011 07:52 PM

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

ctkroeker 11-30-2011 01:40 PM

That looks doable. Does this work on an arecord stream that is recording?
i.e. I have arecord doing this every two hours
Code:

/usr/bin/arecord -f cd -c1 -r22050 -d 7195 | lame -V 3 -h - /home/server/recordings/$(date +%m-%d_%H.%M).mp3
Just append | silent_detect.php at the end of that line?

BTW, your script seems to be down.

jlinkels 11-30-2011 02:37 PM

No, lame doesn't output anything.

You can pipe into silence.php and then pipe the output of silence.php into lame.

What do you mean with "the script is down"? It won't work unmodified.

jlinkels

ctkroeker 11-30-2011 02:40 PM

Quote:

Originally Posted by jlinkels (Post 4538506)
What do you mean with "the script is down"? It won't work unmodified.

http://mail.linkels.net/~jlinkels/links/CheckLine.php displays:
Code:

<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 />


jlinkels 11-30-2011 03:24 PM

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.

jlinkels

OdinnBurkni 06-05-2012 09:49 AM

Detecting silence
 
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?

jlinkels 06-05-2012 07:46 PM

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.

jlinkels

OdinnBurkni 06-06-2012 03:11 AM

Thank you jlinkels.
My next question is... how will I check the file for these values? Any pointers, please?

OdinnBurkni 06-06-2012 04:20 AM

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?

Xeratul 11-16-2012 11:16 AM

Would not it be possible to code the same on Linux.

http://www.pira.cz/eng/silence.htm


it must be probably possible.


Look audacious displays you bar the the khz of the sound, so why not to detect that all are down to a given background...


All times are GMT -5. The time now is 10:12 PM.