#!/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