[Sugar-devel] [PATCH Sugar] Close audio device after text to speech - OLPC #11829

Simon Schampijer simon at schampijer.de
Mon May 7 05:21:03 EDT 2012


On 05/04/2012 11:34 PM, godiard at sugarlabs.org wrote:
> From: Gonzalo Odiard<godiard at gmail.com>
>
> In xo with alsa, if we keep opened the audio device after
> doing tts, other activities can't use it.
> We need close the device after the eof message is received,
> because the message came a little before the sound has finished.

That sounds suspicious to me. I looked at the documentation [1][2] and 
they seem to wait for the 'gst.MESSAGE_EOS' message in order to release 
the device 'set_state(gst.STATE_NULL)'.

I did do a quick test and changed our code to behave the same and it 
seems to work:

diff --git a/src/jarabe/model/speech.py b/src/jarabe/model/speech.py
index ffc108c..5b5518e 100644
--- a/src/jarabe/model/speech.py
+++ b/src/jarabe/model/speech.py
@@ -169,11 +169,14 @@ class _GstSpeechPlayer(gobject.GObject):

          bus = self._pipeline.get_bus()
          bus.add_signal_watch()
-        bus.connect('message::element', self.__pipe_message_cb)
+        bus.connect('message', self.__pipe_message_cb)

      def __pipe_message_cb(self, bus, message):
-        if message.structure.get_name() == 'espeak-mark' and \
-                message.structure['mark'] == 'end':
+        if message.type == gst.MESSAGE_EOS:
+            self._pipeline.set_state(gst.STATE_NULL)
+            self.emit('stop')
+        elif message.type == gst.MESSAGE_ERROR:
+            self._pipeline.set_state(gst.STATE_NULL)
              self.emit('stop')

Regards,
    Simon

[1] 
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-helloworld.html#section-helloworld
[2] http://pygstdocs.berlios.de/pygst-tutorial/playbin.html


More information about the Sugar-devel mailing list