diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-02-20 02:41:29 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-02-20 02:41:29 (GMT) |
commit | 8433dd156c9a840271df560a3dddc9332c3a221c (patch) | |
tree | d2ce6323ab7e3e0f5b1082b22e52ff09f266e239 /speech.py | |
parent | 6083496794da2b4d5d39c3528143dc08ce4b92c0 (diff) |
Add Play/Pause button
Diffstat (limited to 'speech.py')
-rw-r--r-- | speech.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/speech.py b/speech.py new file mode 100644 index 0000000..f5d2b34 --- /dev/null +++ b/speech.py @@ -0,0 +1,82 @@ +#! /usr/bin/env python + +# Copyright (C) 2008 James D. Simmons +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import gtk +import time +import threading + +supported = True + +try: + import speechd +except: + supported = False + +done = True + +class EspeakThread(threading.Thread): + def run(self): + "This is the code that is executed when the start() method is called" + global done + self.client = None + try: + self.client = speechd.SSIPClient('readetexts') + self.client._conn.send_command('SET', speechd.Scope.SELF, 'SSML_MODE', "ON") + if self.speech_voice: + self.client.set_language(self.speech_voice[1]) + self.client.set_rate(self.speech_rate) + self.client.set_pitch(self.speech_pitch) + self.client.speak(self.words_on_page, self.next_word_cb, (speechd.CallbackType.INDEX_MARK, + speechd.CallbackType.END)) + done = False + while not done: + time.sleep(0.1) + self.cancel() + self.client.close() + except: + print 'speech-dispatcher client not created' + + def set_words_on_page(self, words): + self.words_on_page = words + + def set_activity(self, activity): + self.activity = activity + + def set_speech_options(self, speech_voice, speech_pitch, speech_rate): + self.speech_rate = speech_rate + self.speech_pitch = speech_pitch + self.speech_voice = speech_voice + + def cancel(self): + if self.client: + try: + self.client.cancel() + except: + print 'speech dispatcher cancel failed' + + def next_word_cb(self, type, **kargs): + global done + if type == speechd.CallbackType.INDEX_MARK: + mark = kargs['index_mark'] + word_count = int(mark) + gtk.gdk.threads_enter() + self.activity.highlight_next_word(word_count) + gtk.gdk.threads_leave() + elif type == speechd.CallbackType.END: + self.activity.reset_current_word() + done = True |