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 /speech_dispatcher.py | |
parent | 5d9a3f972013bb4b163f29cdc305e79b63a1fb30 (diff) |
Unify speech interface to simplify adoption of gst
Diffstat (limited to 'speech_dispatcher.py')
-rw-r--r-- | speech_dispatcher.py | 31 |
1 files changed, 21 insertions, 10 deletions
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 |