Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/PrestametuVoz.activity/sonido.py
blob: 8d933c16450b2baeaefd57080bdedae4ffca9200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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