diff options
author | Esteban Arias <earias@plan.ceibal.edu.uy> | 2010-09-20 18:16:24 (GMT) |
---|---|---|
committer | Esteban Arias <earias@plan.ceibal.edu.uy> | 2010-09-20 18:16:24 (GMT) |
commit | 07341d2801bb138c53b6465a5492a80621d7073d (patch) | |
tree | 146c3acacf7b098401024acc9cb45e97542ce5d0 /PrestametuVoz.activity/sonido.py |
first commit
Diffstat (limited to 'PrestametuVoz.activity/sonido.py')
-rw-r--r-- | PrestametuVoz.activity/sonido.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/PrestametuVoz.activity/sonido.py b/PrestametuVoz.activity/sonido.py new file mode 100644 index 0000000..8d933c1 --- /dev/null +++ b/PrestametuVoz.activity/sonido.py @@ -0,0 +1,42 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +''' Función para reproducir sonido ''' + +import pygst +#pygst.require("0.10") +import sys, gst, gobject + +gobject.threads_init() + +def reproducir(sonido): + ''' Reproduce el sonido mediante pygst ''' + + pipestr = "filesrc location= %s ! oggdemux ! vorbisdec ! audioconvert ! alsasink" % sonido + + try: + pipeline = gst.parse_launch(pipestr) + except gobject.GError, e: + print "No se pudo crear tubería,", str(e) + return -1 + + def eventos(bus, msg): + t = msg.type + if t == gst.MESSAGE_EOS: + loop.quit() + elif t == gst.MESSAGE_ERROR: + e, d = msg.parse_error() + print "ERROR:", e + loop.quit() + return True + + pipeline.get_bus().add_watch(eventos) + pipeline.set_state(gst.STATE_PLAYING) + loop = gobject.MainLoop() + try: + loop.run() + except KeyboardInterrupt: + pass + pipeline.set_state(gst.STATE_NULL) + return 0 + + |