Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/las.py
diff options
context:
space:
mode:
authorAssim <assim@localhost.localdomain>2009-03-30 05:47:13 (GMT)
committer Assim <assim@localhost.localdomain>2009-03-30 05:47:13 (GMT)
commitf10e907e90b7555110d96c74c2d3341d60fd69a0 (patch)
treebbbc48836f3da39453bb8148d4896bd385ac4314 /las.py
parentbae7e68f664f99d520fda046eea6ca489ea2863f (diff)
speech dispatcher dependency removed
Diffstat (limited to 'las.py')
-rwxr-xr-xlas.py131
1 files changed, 69 insertions, 62 deletions
diff --git a/las.py b/las.py
index 04bf17e..1eece34 100755
--- a/las.py
+++ b/las.py
@@ -4,7 +4,8 @@ import os
import dbus
import random
import time
-import speechd
+import espeak
+from espeak import espeak
import commands
import simplejson
#import csnd
@@ -52,12 +53,14 @@ class Listenspell():
self.points = 0
self.words_played = 0
self.words_correct = 0
- self.config_file = 'ls-speechd-config'
+ self.config_file = 'ls-espeak-config'
self.path = "."
- self.speechd_init = False
- self.__speechd_default_config = {'pitch':0, 'rate':0, 'language':'en', 'volume':100, 'voice':'MALE1',
- 'spelling':False, 'punctuation':speechd.PunctuationMode.SOME }
- self.__speechd_config = self.__speechd_default_config
+ self.espeak_init = False
+ self.espeak_obj = espeak()
+ #self.__espeak_default_config = {'pitch':0, 'rate':0, 'language':'en', 'volume':100, 'voice':'MALE1',
+ #'spelling':False, 'punctuation':espeak.PunctuationMode.SOME }
+ self.__espeak_default_config = {'pitch':0, 'rate':0, 'language':'en', 'volume':100}
+ self.__espeak_config = self.__espeak_default_config
def load_db(self, SQLiteDB):
if self.path == ".":
@@ -160,116 +163,120 @@ class Listenspell():
return phnm
- def get_speechd_config(self, default =0):
+ def get_espeak_config(self, default =0):
if default == 1:
- return self.__speechd_default_config
+ return self.__espeak_default_config
else:
- return self.__speechd_config
+ return self.__espeak_config
- def load_speechd_config(self):
+ def load_espeak_config(self):
try:
fp = open(self.path + self.config_file)
except IOError:
#File doesn't exist, create it and write default config
fp = open(self.path + self.config_file, 'w', 0)
- speech_config = self.get_speechd_config(1)
+ speech_config = self.get_espeak_config(1)
simplejson.dump(speech_config, fp)
else:
speech_config = simplejson.load(fp)
for attr in speech_config:
- self.speechd_config(attr, speech_config[attr])
+ self.espeak_config(attr, speech_config[attr])
fp.close()
return speech_config
- def __start_speechd(self):
- try:
- self.client = speechd.SSIPClient('spd-test')
- self.client.set_output_module('espeak')
- self.client.set_language('en')
- self.client.set_punctuation(speechd.PunctuationMode.SOME)
- self.speech_state = None
- except dbus.exceptions.DBusException:
- print "Speech Dispatcher is not turned on."
- return False
- self.speechd_init = True
+ #def __start_espeak(self):
+ #try:
+ #self.client = espeak.SSIPClient('spd-test')
+ #self.client.set_output_module('espeak')
+ #self.client.set_language('en')
+ #self.client.set_punctuation(espeak.PunctuationMode.SOME)
+ #self.speech_state = None
+ #except dbus.exceptions.DBusException:
+ #print "Speech Dispatcher is not turned on."
+ #return False
+ #self.espeak_init = True
- def __set_speechd_config(self, attribute = None, value = None, mode = 'one', config_obj = None):
+ def __set_espeak_config(self, attribute = None, value = None, mode = 'one', config_obj = None):
if mode == 'one':
if attribute == None or value == None:
return False
#print attribute + ":" + str(value)
- self.__speechd_config[attribute] = value
+ self.__espeak_config[attribute] = value
fp = open(self.path + self.config_file, 'w', 0)
- simplejson.dump(self.__speechd_config, fp)
+ simplejson.dump(self.__espeak_config, fp)
fp.close()
elif mode == 'all':
if config_obj == None:
return False
fp = open(self.path + self.config_file, 'w', 0)
- self.__speechd_config = config_obj
- simplejson.dump(self.__speechd_config, fp)
+ self.__espeak_config = config_obj
+ simplejson.dump(self.__espeak_config, fp)
fp.close()
- def speechd_config(self, attribute = None, data = None):
+ def espeak_config(self, attribute = None, data = None):
if attribute == None or data == None:
return False
- if self.speechd_init == False:
- if self.__start_speechd() == False:
- return False
+ #if self.espeakinit == False:
+ #if self.__start_espeak() == False:
+ #return False
attribute_list = ['pitch', 'rate', 'volume', 'voice', 'output_module',
'language', 'punctuation', 'spelling', 'synthesis_voice']
if attribute in attribute_list:
try:
- self.__set_speechd_config(attribute, data)
+ self.__set_espeak_config(attribute, data)
if attribute == "pitch":
- self.client.set_pitch(int(data)) #-100 to 100
+ self.espeak_obj.set_pitch(int(data)) # 0 to 99
+ #self.client.set_pitch(int(data)) #-100 to 100
elif attribute == "rate":
- self.client.set_rate(int(data)) # -100 to 100
+ self.espeak_obj.set_speed(int(data)) # 80 to 370
+ #self.client.set_rate(int(data)) # -100 to 100
elif attribute == "volume":
- self.client.set_volume(int(data))#-100 to 100
- elif attribute == "voice":
- self.client.set_voice(str(data))#(FE)MALE(1,2,3), CHILD_(FE)MALE
- elif attribute == "output_module":
- self.client.set_output_module(str(data))
- elif attribute == "language":
- self.client.set_language(str(data))
- elif attribute == "punctuation":
- self.client.set_punctuation(data)
- elif attribute == "spelling":
- self.client.set_spelling(bool(data)) # True or False
- elif attribute == "synthesis_voice":
- self.client.set_synthesis_voice(str(data))#self.client.list_synthesis_voices()
+ self.espeak_obj.set_amplitude(int(data)) # 0 to 200
+ #self.client.set_volume(int(data)) #-100 to 100
+ #elif attribute == "voice":
+ #self.client.set_voice(str(data))#(FE)MALE(1,2,3), CHILD_(FE)MALE
+ #elif attribute == "output_module":
+ #self.client.set_output_module(str(data))
+ #elif attribute == "language":
+ #self.client.set_language(str(data))
+ #elif attribute == "punctuation":
+ #self.client.set_punctuation(data)
+ #elif attribute == "spelling":
+ #self.client.set_spelling(bool(data)) # True or False
+ #elif attribute == "synthesis_voice":
+ #self.client.set_synthesis_voice(str(data))#self.client.list_synthesis_voices()
except AssertionError, e:
print "Assertion Error: " + str(e) + ":" + str(attribute) + ":" + str(data)
return False
else: return False
- def __speechd_callback(self,callback_type):
- self.speech_state = callback_type
+ #def __espeak_callback(self,callback_type):
+ #self.speech_state = callback_type
def say_text(self, text, wait= True):
#wait: to wait for the text to be spoken or not
#os.popen("espeak " + text)
- if self.speechd_init == False:
- if self.__start_speechd() == False:
- return False
+ #if self.espeak_init == False:
+ #if self.__start_espeak() == False:
+ #return False
text = str(text)
- self.speech_state = None
-
- self.client.speak(text, callback=self.__speechd_callback,event_types=(speechd.CallbackType.BEGIN,
- speechd.CallbackType.CANCEL,
- speechd.CallbackType.END))
- if wait == True:
- while(self.speech_state != "end"):
- time.sleep(1)
+ #self.speech_state = None
+ self.espeak_obj.speak(text)
+ #self.client.speak(text, callback=self.__espeak_callback,event_types=(espeak.CallbackType.BEGIN,
+ #espeak.CallbackType.CANCEL,
+ #espeakCallbackType.END))
+ #if wait == True:
+ #i = len(text)
+ ##while(self.speech_state != "end"):
+ #time.sleep(i)
@@ -286,5 +293,5 @@ class Listenspell():
self.word_obj.exit_game()
self.dict_obj.exit_game()
self.say_text("goodbye")
- self.client.close()
+ #self.client.close()
sys.exit()