LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 11-22-2011, 08:23 AM   #1
ctkroeker
Senior Member
 
Registered: May 2005
Posts: 1,565
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
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
Posts: 1,565

Original Poster
Blog Entries: 1

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
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
Posts: 1,565

Original Poster
Blog Entries: 1

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
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
 
Old 06-05-2012, 09:49 AM   #7
OdinnBurkni
Member
 
Registered: Feb 2007
Location: Iceland
Distribution: Fedora 14, CentOS, FreeNAS
Posts: 127

Rep: Reputation: 20
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?
 
Old 06-05-2012, 07:46 PM   #8
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
 
Old 06-06-2012, 03:11 AM   #9
OdinnBurkni
Member
 
Registered: Feb 2007
Location: Iceland
Distribution: Fedora 14, CentOS, FreeNAS
Posts: 127

Rep: Reputation: 20
Thank you jlinkels.
My next question is... how will I check the file for these values? Any pointers, please?
 
Old 06-06-2012, 04:20 AM   #10
OdinnBurkni
Member
 
Registered: Feb 2007
Location: Iceland
Distribution: Fedora 14, CentOS, FreeNAS
Posts: 127

Rep: Reputation: 20
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?
 
Old 11-16-2012, 11:16 AM   #11
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
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...
 
  


Reply

Tags
arecord, audio silence, sox



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 On
HTML code is 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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:50 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration