Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/speech.py
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-03-08 23:19:34 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-03-08 23:19:34 (GMT)
commit18296c8d83f9ae63c7aaf0128f091da896c1e2f7 (patch)
tree190cae329c8cfed35fe51af4fd13409132ce0812 /speech.py
parent9d1e3592b54fec7e06dd9ffd18c3cd5cb7f334b1 (diff)
Isolate speech-dispatcher code
Diffstat (limited to 'speech.py')
-rw-r--r--speech.py82
1 files changed, 14 insertions, 68 deletions
diff --git a/speech.py b/speech.py
index 5084826..72fc5b9 100644
--- a/speech.py
+++ b/speech.py
@@ -1,5 +1,3 @@
-#! /usr/bin/env python
-
# Copyright (C) 2008 James D. Simmons
#
# This program is free software; you can redistribute it and/or modify
@@ -16,73 +14,21 @@
# 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 __init__(self, stop_cb):
- threading.Thread.__init__(self)
- self.stop_cb = stop_cb
-
- 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()
- self.stop_cb()
- 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
+highlight_cb = None
+reset_cb = None
+voice = None
+pitch = None
+rate = None
- 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()
- self.activity.reset_play_button()
- done = True
+try:
+ import gst
+ gst.element_factory_make('espeak')
+ from speech-gst import *
+except:
+ try:
+ from speech-dispatcher import *
+ except:
+ supported = False