Silence Detection (or how I came to love GStreamer)

Saturday, June 9, 2007 22:51 - Code

I have been slacking on so many front lately it is kind of worrying but progress were made nevertheless, sometimes where I didn't expect any... (sorry library.gnome.org, I will get back to you).

So I have been helping a local radio with their computer stuff for almost two years now and things are moving at good pace now, I hope to soon get more involved with the audio side (but computer problems use to happen whenever I am thinking about that, so I am fairly conservative there).

I was there Friday and a "rare but annoying and should be avoidable" problem cropped up, somebody forgot to switch back from the live studio to the nonstop program and silence was broadcasted for almost one hour. Bad.

We looked for two minutes for a silence detection program but the day was over and we were tired so we left at that. But what could I do on a Saturday evening when you can't go out because you must get up very early next morning ? Right, getting back to that and writing it myself.

And that is so easy, thanks to GStreamer.

def bus_event(bus, message, *args):
    peak = message.structure['peak'][0]
    if peak < -50:
        print 'silence on the cable! help!'
    return True

mainloop = gobject.MainLoop()

s = 'gnomevfssrc location="http://local-stream:8000/local.ogg" ! '\
      'oggdemux ! vorbisdec ! audioconvert ! '\
      'level message=true interval=5000000000 ! fakesink'

pipeline = gst.parse_launch(s)
pipeline.get_bus().add_signal_watch()
i = pipeline.get_bus().connect('message::element', bus_event)
pipeline.set_state(gst.STATE_PLAYING)
mainloop.run()

This is not the actual script I have running (mine has logging and more subtle status change actions) but the basic is there.

On the 16th of January 2004, at the Barbican in London, the BBC Symphony Orchestra, gave the UK's first orchestral performance of this work [4'33" by John Cage, which consists of four and a half minutes of silence]. The performance was broadcast live on BBC3 Radio and one of the main challenges was the radio's emergency backup systems which are designed to switch on whenever apparent silence is detected. They had to be switched off for the sole purpose of this performance.

-- http://en.wikipedia.org/wiki/4'33%22

Comment by Thomas Thurman on June 10, 2007 1:27

Wow! Very cool! Here is a nice use-case that I never thought about!

Comment by Amirouche B. on June 10, 2007 4:46

Thomas: yeah, I didn't know about that occurence but we actually joked about sth like this since there are quite a few experimental stuffs going on the radio, and silence is totally a thing they could do. This prevents to do anything drastic whenever the situation is detected.

Comment by Frédéric Péters on June 10, 2007 7:01

Comments on this entry have been closed.