Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/PrestametuVoz.activity/sonido.py
diff options
context:
space:
mode:
Diffstat (limited to 'PrestametuVoz.activity/sonido.py')
-rw-r--r--PrestametuVoz.activity/sonido.py42
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
+
+