LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
LinkBack Search this Thread
Old 11-22-2011, 08:23 AM   #1
ctkroeker
Senior Member
 
Registered: May 2005
Location: Paraguay
Posts: 1,563
Blog Entries: 1

Rep: Reputation: 50
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!
 
Old 11-23-2011, 07:52 PM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,482

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
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
 
Old 11-30-2011, 01:40 PM   #3
ctkroeker
Senior Member
 
Registered: May 2005
Location: Paraguay
Posts: 1,563
Blog Entries: 1

Original Poster
Rep: Reputation: 50
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.
 
Old 11-30-2011, 02:37 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,482

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
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
 
Old 11-30-2011, 02:40 PM   #5
ctkroeker
Senior Member
 
Registered: May 2005
Location: Paraguay
Posts: 1,563
Blog Entries: 1

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by jlinkels View Post
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 />
 
Old 11-30-2011, 03:24 PM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,482

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
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
 
  


Reply

Tags
arecord, audio silence, sox


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recording Audio with Silence Detection? devmoc Linux - Software 4 09-25-2009 11:41 AM
Audio Recorder software with sound detection??? jantman Linux - Software 1 03-20-2008 08:31 AM
Acer extensa 2900 audio problem detection man1979 Linux - Hardware 1 08-22-2005 10:34 AM
Computer Plays Silence when Playing Audio CD TGWDNGHN Linux - Hardware 9 07-16-2005 02:23 AM
audio THD detection in linux with ALSA monohouse Linux - Software 0 02-16-2005 12:03 PM


All times are GMT -5. The time now is 03:09 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration