Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/las.py
diff options
context:
space:
mode:
Diffstat (limited to 'las.py')
-rwxr-xr-xlas.py113
1 files changed, 71 insertions, 42 deletions
diff --git a/las.py b/las.py
index 96fd52e..39afbb1 100755
--- a/las.py
+++ b/las.py
@@ -46,50 +46,44 @@ class _GetchWindows:
class Listenspell():
- def __init__(self, SQLiteDB):
-
+ def __init__(self):
self.skill_level = 0
- self.level_threshold = 5
self.points = 0
self.words_played = 0
self.words_correct = 0
+ self.path = "."
self.speechd_init = False
- self.dict_obj = Dict(SQLiteDB) #Always intitiate first Dict object then Word object
+ self.__speechd_default_config = {'pitch':0, 'rate':0, 'language':'en', 'volume':100, 'voice':'',
+ 'spelling':False, 'punctuation':speechd.PunctuationMode.SOME }
+ self.__speechd_config = {'pitch':0, 'rate':0, 'language':'en', 'volume':100, 'voice':'',
+ 'spelling':False, 'punctuation':speechd.PunctuationMode.SOME }
+
+ def load_db(self, SQLiteDB):
+ if self.path == ".":
+ return False
+ #print self.path + SQLiteDB
+ self.dict_obj = Dict(self.path + SQLiteDB) #Always intitiate first Dict object then Word object
self.word_obj = Word()
-
+
+ def set_path(self, path):
+ if path != "":
+ self.path = path + "/"
+ else:
+ self.path = path
def play_sound(self,event):
- #file= event + '.wav'
- #from wave import open as waveOpen
- #from ossaudiodev import open as ossOpen
- #s = waveOpen(file,'rb')
- #(nc,sw,fr,nf,comptype, compname) = s.getparams( )
- #dsp = ossOpen('/dev/dsp','w')
- #try:
- #from ossaudiodev import AFMT_S16_NE
- #except ImportError:
- #if byteorder == "little":
- #AFMT_S16_NE = ossaudiodev.AFMT_S16_LE
- #else:
- #AFMT_S16_NE = ossaudiodev.AFMT_S16_BE
- #dsp.setparameters(AFMT_S16_NE, nc, fr)
- #data = s.readframes(nf)
- #s.close()
- #dsp.write(data)
- #dsp.close()
-
- os.popen("aplay --quiet " + event + ".wav")
- #if event == "begin":
- #os.popen("aplay --quiet begin.wav")
- #elif event == "correct":
- #os.popen("aplay --quiet correct.wav")
- #elif event == "incorrect":
- #os.popen("aplay --quiet incorrect.wav")
+ os.popen("aplay --quiet " + self.path + event + ".wav")
def set_skill_level(self,level):
self.skill_level = level
+ self.reset_counters()
+ def reset_counters(self):
+ self.points = 0
+ self.words_played = 0
+ self.words_correct = 0
+
def get_skill_level(self):
return self.skill_level
@@ -149,21 +143,28 @@ class Listenspell():
elif attribute == "phnm":
phnm = self.word_obj.get_phoneme()
if phnm == None:
- phnm = self.get_phoneme(self.word_obj.get_word())
+ phnm = self.__get_phoneme(self.word_obj.get_word())
return phnm
else:
(phoneme, is_correct) = phnm
return phoneme
else: return False
- def get_phoneme(self, word = None):
+ def __get_phoneme(self, word = None):
if word == None:
return False
phnm = commands.getoutput("/usr/bin/espeak -q -x " + word)
self.word_obj.update_phoneme(phnm)
return phnm
- def start_speechd(self):
+
+ def get_speechd_config(self, default =0):
+ if default == 1:
+ return self.__speechd_default_config
+ else:
+ return self.__speechd_config
+
+ def __start_speechd(self):
try:
self.client = speechd.SSIPClient('spd-test')
self.client.set_output_module('espeak')
@@ -173,23 +174,51 @@ class Listenspell():
except dbus.exceptions.DBusException:
print "Speech Dispatcher is not turned on."
return False
+ self.speechd_init = True
+
+ def speechd_config(self, attribute = None, data = None):
+
+ if attribute == None or data == None:
+ return False
- def callback(self,callback_type):
+ if self.speechd_init == False:
+ if self.__start_speechd() == False:
+ return False
+
+ if attribute == "pitch":
+ self.client.set_pitch(data) #-100 to 100
+ elif attribute == "rate":
+ self.client.set_rate(data) # -100 to 100
+ elif attribute == "volume":
+ self.client.set_volume(data)#-100 to 100
+ elif attribute == "voice":
+ self.client.set_voice(data)#(FE)MALE(1,2,3), CHILD_(FE)MALE
+ elif attribute == "output_module":
+ self.client.set_output_module(data)
+ elif attribute == "language":
+ self.client.set_language(data)
+ elif attribute == "punctuation":
+ self.client.set_punctuation(data)
+ elif attribute == "spelling":
+ self.client.set_spelling(data) # True or False
+ elif attribute == "synthesis_voice":
+ self.client.set_synthesis_voice(data)#self.client.list_synthesis_voices()
+ else: return False
+
+ def __speechd_callback(self,callback_type):
self.speech_state = callback_type
- def say_text(self, text, wait= True, is_phoneme = False):
+ 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:
+ if self.__start_speechd() == False:
return False
- self.speechd_init = True
text = str(text)
- if is_phoneme:
- text = "[" + text + "]"
-
- self.client.speak(text, callback=self.callback,event_types=(speechd.CallbackType.BEGIN,
+ 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: