diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-03-09 02:25:08 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-03-09 02:25:08 (GMT) |
commit | 05899840483e1911b4e90180b3978c159a8cd00f (patch) | |
tree | 3efad6c8bc855fae01b97af8b69b9eb66989a6e8 | |
parent | 5d9a3f972013bb4b163f29cdc305e79b63a1fb30 (diff) |
Unify speech interface to simplify adoption of gst
-rwxr-xr-x | ReadEtextsActivity.py | 7 | ||||
-rw-r--r-- | readtoolbar.py | 8 | ||||
-rw-r--r-- | speech.py | 3 | ||||
-rw-r--r-- | speech_dispatcher.py | 31 |
4 files changed, 31 insertions, 18 deletions
diff --git a/ReadEtextsActivity.py b/ReadEtextsActivity.py index 7290920..435017d 100755 --- a/ReadEtextsActivity.py +++ b/ReadEtextsActivity.py @@ -156,6 +156,9 @@ class ReadEtextsActivity(activity.Activity): elif self._object_id is None: # Not joining, not resuming self._show_journal_object_picker() + + speech.highlight_cb = self.highlight_next_word + speech.reset_cb = self.reset_play_button def _show_journal_object_picker(self): """Show the journal object picker to load a document. @@ -216,7 +219,7 @@ class ReadEtextsActivity(activity.Activity): self.textview.grab_focus() def delete_cb(self, widget, event): - speech.done = True + speech.stop() return False def highlight_next_word(self, word_count): @@ -261,7 +264,7 @@ class ReadEtextsActivity(activity.Activity): if keyname == 'minus': self.font_decrease() return True - if speech.done == False: + if speech.is_stopped() == False: # If speech is in progress, ignore other keys. return True if keyname == 'KP_Right': diff --git a/readtoolbar.py b/readtoolbar.py index d74a78a..b34dcae 100644 --- a/readtoolbar.py +++ b/readtoolbar.py @@ -329,9 +329,7 @@ class SpeechToolbar(gtk.Toolbar): widget.set_icon_widget(images[int(widget.get_active())]) if widget.get_active(): - if speech.done: - speech.play(self.activity.add_word_marks(), - self.activity.highlight_next_word, - self.activity.reset_play_button) + if speech.is_stopped(): + speech.play(self.activity.add_word_marks()) else: - speech.done = True + speech.stop() @@ -19,7 +19,6 @@ import logging _logger = logging.getLogger('read-etexts-activity') supported = True -done = True try: import gst @@ -38,3 +37,5 @@ voice = None pitch = PITCH_DEFAULT rate = RATE_DEFAULT +highlight_cb = None +reset_cb = None diff --git a/speech_dispatcher.py b/speech_dispatcher.py index c12aca5..88d620f 100644 --- a/speech_dispatcher.py +++ b/speech_dispatcher.py @@ -32,6 +32,8 @@ PITCH_MIN = -100 PITCH_MAX = 100 PITCH_DEFAULT = 0 +done = True + def voices(): try: client = speechd.SSIPClient('readetextstest') @@ -53,17 +55,22 @@ def say(words): except Exception, e: _logger.warning('speech dispatcher not running: %s' % e) -def play(words, highlight_cb, reset_cb): +def is_stopped(): + return done + +def stop(): + global done + done = True + +def play(words): global thread - thread = EspeakThread(words, highlight_cb, reset_cb) + thread = EspeakThread(words) thread.start() class EspeakThread(threading.Thread): - def __init__(self, words, highlight_cb, reset_cb): + def __init__(self, words): threading.Thread.__init__(self) self.words = words - self.highlight_cb = highlight_cb - self.reset_cb = reset_cb def run(self): "This is the code that is executed when the start() method is called" @@ -77,8 +84,9 @@ class EspeakThread(threading.Thread): self.client.set_pitch(speech.pitch) self.client.speak(self.words, self.next_word_cb, (speechd.CallbackType.INDEX_MARK, speechd.CallbackType.END)) - speech.done = False - while not speech.done: + global done + done = False + while not done: time.sleep(0.1) self.cancel() self.client.close() @@ -97,8 +105,11 @@ class EspeakThread(threading.Thread): mark = kargs['index_mark'] word_count = int(mark) gtk.gdk.threads_enter() - self.highlight_cb(word_count) + speech.highlight_cb(word_count) gtk.gdk.threads_leave() elif type == speechd.CallbackType.END: - self.reset_cb() - speech.done = True + gtk.gdk.threads_enter() + speech.reset_cb() + gtk.gdk.threads_leave() + global done + done = True |