From 07341d2801bb138c53b6465a5492a80621d7073d Mon Sep 17 00:00:00 2001 From: Esteban Arias Date: Mon, 20 Sep 2010 18:16:24 +0000 Subject: first commit --- (limited to 'PrestametuVoz.activity/sonido.py') 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 + + -- cgit v0.9.1