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

2012-05-07 Thread Simon Schampijer

On 05/04/2012 11:34 PM, godi...@sugarlabs.org wrote:

From: Gonzalo Odiardgodi...@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
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


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

2012-05-07 Thread Gonzalo Odiard
Ok, if we will use EOS message, we don't need add the end marl anymore.
I think i had used this mark, because iin my previous test,
didn't received the EOS signal at times, But now I tested it again and
received the message, then I am ok with doing the change.
A updated patch should be:

diff --git a/src/jarabe/model/speech.py b/src/jarabe/model/speech.py
index ffc108c..1cb0ad4 100644
--- a/src/jarabe/model/speech.py
+++ b/src/jarabe/model/speech.py
@@ -169,18 +169,20 @@ 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')

 def speak(self, pitch, rate, voice_name, text):
 # TODO workaround for http://bugs.sugarlabs.org/ticket/1801
 if not [i for i in text if i.isalnum()]:
 return
-text = text + 'mark name=end/mark'

 self.make_pipeline('espeak name=espeak ! autoaudiosink')
 src = self._pipeline.get_by_name('espeak')
-- 
1.7.10.1
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


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

2012-05-04 Thread godiard
From: Gonzalo Odiard godi...@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.

Signed-off-by: Gonzalo Odiard gonz...@laptop.org
---
 src/jarabe/model/speech.py |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/jarabe/model/speech.py b/src/jarabe/model/speech.py
index ffc108c..46ce483 100644
--- a/src/jarabe/model/speech.py
+++ b/src/jarabe/model/speech.py
@@ -155,10 +155,11 @@ class _GstSpeechPlayer(gobject.GObject):
 
 def stop_sound_device(self):
 if self._pipeline is None:
-return
+return False
 
 self._pipeline.set_state(gst.STATE_NULL)
 self.emit('stop')
+return False
 
 def make_pipeline(self, command):
 if self._pipeline is not None:
@@ -174,6 +175,7 @@ class _GstSpeechPlayer(gobject.GObject):
 def __pipe_message_cb(self, bus, message):
 if message.structure.get_name() == 'espeak-mark' and \
 message.structure['mark'] == 'end':
+gobject.timeout_add_seconds(1, self.stop_sound_device)
 self.emit('stop')
 
 def speak(self, pitch, rate, voice_name, text):
-- 
1.7.10

___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel