speechd-discuss
[Top][All Lists]
Advanced

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

Pygtk does not play nicely with speech-dispatcher


From: James Simmons
Subject: Pygtk does not play nicely with speech-dispatcher
Date: Thu, 24 Apr 2008 09:16:17 -0500

I have been working on a Pygtk pgrogram for the OLPC project which is a 
reading program for Project Gutenberg Etexts.  Several people on the 
OLPC mailing list suggested enhancing it to work with speech-dispatcher 
so that the program could read the texts aloud, at the same time 
highlighting the word as it is spoken.  They felt it would be useful to 
students trying to improve their reading skills, etc.  What I have found 
is that getting the program to read aloud is easy, getting a Pygtk 
program to highlight words one a a time is easy, but getting the two to 
work together might be impossible.

Speech-dispatcher runs in its own thread.  It has callbacks that I have 
configured to execute a Python method every time a word ends.  Using 
this it *should* be trivial to highlight the word as it is spoken.  
Trouble is, when the Pygtk event loop is allowed to run at the same time 
as speech-dispatcher, none of the callbacks are ever invoked.  If I do a 
wait loop after invoking speech-dispatcher, then all of the callbacks 
work but the screen does not get updated to show the words being 
highlighted.  Only the final word on the page gets highlighted.  Hynek 
Hanke of the speech-dispatcher project has noticed that socket.recv() 
does not work in speech-dispatcher if it is allowed to run at the same 
time as the event loop.

I can supply code to demonstrate this problem.  I am hoping that one of 
you can suggest a good workaround.

Thanks,

James Simmons



Hynek Hanke wrote:

>
> Hello James,
>
> it is an interesting problem. I think pygtk needs to be fixed if it
> seems to behave so badly with other libraries using threads.
> This has little to do with speech callbacks specifically. More
> important is the thing that when you run basic system functions
> like socket.recv() from other threads, they behave badly.
> Would you like to raise this issue with the PyGTK developers
> to see if it is possible to fix it or to use PyGTK in some other
> way that avoids the conflict?
>
> As a workaround, you can try to avoid the pygtk loop and do
> your own asynchronous thread to highlight the words. Threads
> are easy in Python. However, unless we find out where in
> PyGTK the problem lies exactly, it is always possible, that you will
> run into the very same problems and they will prevent your
> thread to work correctly.
>
> Anyway, old or new implementation of speechd, threads will
> always be used in the python communication library, since they
> are technically necessary to handle asynchronous callbacks.
> So it would be very useful to try to find a solution with pygtk.
>
> With regards,
> Hynek Hanke






reply via email to

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