speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with "end" callback in Python


From: James Simmons
Subject: Problems with "end" callback in Python
Date: Fri, 18 Apr 2008 09:43:47 -0500

Hemant,

Last night I figured out a way to avoid the conflicts between 
speech-dispatcher and the pygtk event loop.  I tried it out this morning 
and it works, mostly.  What I do is after I send the request to SD I 
wait in a loop until the callback is received, like this:

self.finished_flag = False
self.client.speak(word, callback=self.finished_speaking_cb, 
event_types=(speechd.CallbackType.END))
while self.finished_flag != True:
    gtk.events_pending()
    time.sleep(.01)

When I do this every callback is received, the words are highlighted 
properly, and the words are spoken.  I can stop and start speech at any 
time.  Unfortunately the words have long pauses between them.  It sounds 
like the voice of Colossus having a really bad day.  It might actually 
help someone learn to read as it is, but I'm hoping I can figure out how 
to do better.  But it looks like sending words to SD one at a time is 
not such a good idea.

James Simmons


Hemant Goyal wrote:

> Hi,
>
> I think INDEX_MARK could be used to mark off positions in your text to 
> indicate to speech-dispatcher when to return to the callbacks.
>
> I read about that in the python api documentation :
>
> INDEX_MARK = 'index_marks'
>
>    """Index mark events are reported when the place they were
>    included into the text by the client application is reached
>    when speaking them"""
>
>
>  
>
> On the flip side, I think your text buffer might become overfilled 
> with these index markers, and you will also have to neglect them when 
> you re printing the text on screen.
>
> Best,
> Hemant
>
> On Fri, Apr 18, 2008 at 1:43 AM, James Simmons 
> <jim.simmons at walgreens.com <mailto:jim.simmons at walgreens.com>> wrote:
>
>     Hynek,
>
>     I have been looking for an alternative to using
>     gobject.timeout_add() in my program and hit on the idea of trying
>     threads in Python.  I found out that pygtk is not thread safe,
>     hence you need to use gtk.threads_enter() and gtk.threads_leave()
>     before and after you execute any GTK code from another thread.  It
>     sounds like thread support in a pygtk application is problematic.
>      It would help if I could avoid it.
>
>     What would make my life simpler would be a way to invoke speech
>     dispatcher on a word and have the function not return until the
>     word has finished being spoken.  That way I would not have to deal
>     with callbacks and multiple threads.  Another thing that might
>     work is invoking speech dispatcher on an entire page and having a
>     callback called at the end of each word.  That way the calbacks
>     could drive the highlighting of the words, rather than having the
>     logic that highlights the words drive the speaking.  That might
>     actually give more natural sounding results, and would eliminate
>     the need for gobject.timeout_add().
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://lists.freebsoft.org/pipermail/speechd/attachments/20080418/5ca30517/attachment.htm
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]