Coin web de Frédéric Péters

fpeters@0d.be

Silence Detection (or how I came to love GStreamer)

9 juin 2007, 22:51

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.