Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAssim <assim@localhost.localdomain>2008-08-11 22:23:24 (GMT)
committer Assim <assim@localhost.localdomain>2008-08-11 22:23:24 (GMT)
commit3dc8eadf78593a060edb120ba4b82e2548e762a6 (patch)
tree92d2662b0d95bc97bc4de6ebd2f85bc78f12f0cc
parent1d271d881502f5f600239253394809df053db4e2 (diff)
configuration panel enable + json support
-rwxr-xr-xListenSpell.py74
-rwxr-xr-xdict.dbbin13942784 -> 13942784 bytes
-rwxr-xr-xdict.py8
-rwxr-xr-xlas.py92
-rw-r--r--ls-speechd-config1
5 files changed, 114 insertions, 61 deletions
diff --git a/ListenSpell.py b/ListenSpell.py
index 68c8c80..689ce29 100755
--- a/ListenSpell.py
+++ b/ListenSpell.py
@@ -28,7 +28,10 @@ class ListenSpell(activity.Activity):
DBname = "dict.db"
self.las.load_db(DBname)
- self.use_phoneme = False
+
+ self.las.load_speechd_config()
+
+ self.use_phoneme = False
self.load_activity_interface()
self.las.play_sound("begin")
@@ -39,16 +42,7 @@ class ListenSpell(activity.Activity):
def load_activity_interface(self):
- #query = {'title':'listen-spell'}
- #(result, count) = datastore.find(query)
- #md = datastore.DSMetadata()
- #if count > 0:
- #dso = result[0]
- #md = dso.get_metadata()
- #md.get()
-
-
-
+
if self.is_stand_alone:
self.main_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.main_window.connect("destroy", self.destroy)
@@ -56,20 +50,7 @@ class ListenSpell(activity.Activity):
self.main_window.set_title("Listen and Spell")
if not self.is_stand_alone:
- toolbox = activity.ActivityToolbox(self)
- #conf_toolbar = ConfigToolBar()
-
- #mytoolbar = gtk.Toolbar()
- #helpbut = gtk.ToolButton(label = 'help') #Stock help icon
- #helpbut.set_tooltip(_("Get help"))
- #helpbut.connect('clicked', self.help_button_pressed)
- #mytoolbar.insert(helpbut, -1)
- #helpbut.show()
- #mytoolbar.show()
-
-
- #toolbox.add_toolbar("my toolbar",mytoolbar)
-
+ toolbox = activity.ActivityToolbox(self)
self.set_toolbox(toolbox)
toolbox.show_all()
# Set title for our Activity
@@ -213,6 +194,8 @@ class ListenSpell(activity.Activity):
+
+
def _update_configuration(self, widget, attribute ):
if attribute == "voice":
self.las.speechd_config(attribute, widget.get_active_text())
@@ -224,7 +207,7 @@ class ListenSpell(activity.Activity):
self.las.say_text(str(speech_text))
def speech_configuration_button_clicked(self, widget, data = None):
- self.config_dialog = gtk.Dialog("Change Speech Configuration", self,0,(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+ self.config_dialog = gtk.Dialog("Speech Configuration", self,0,(gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
#self.las.say_text("Skill Level")
#vbox = gtk.VBox(False, 8)
#Vbox.set_border_width(8)
@@ -238,9 +221,12 @@ class ListenSpell(activity.Activity):
self.config_dialog.vbox.pack_start(speech_frame, False, False, 0)
- volume_adj = gtk.Adjustment(0, -100, 101, 1, 1, 1)
- rate_adj = gtk.Adjustment(0, -100, 101, 1, 1, 1)
- pitch_adj = gtk.Adjustment(0, -100, 101, 1, 1, 1)
+ speech_config = self.las.get_speechd_config()
+ previous_speechd_config = speech_config
+
+ volume_adj = gtk.Adjustment(float(speech_config['volume']), -100, 101, 1, 1, 1)
+ rate_adj = gtk.Adjustment(float(speech_config['rate']), -100, 101, 1, 1, 1)
+ pitch_adj = gtk.Adjustment(float(speech_config['pitch']), -100, 101, 1, 1, 1)
volume_hscale = gtk.HScale(volume_adj)
@@ -261,7 +247,13 @@ class ListenSpell(activity.Activity):
#hscale4 = gtk.HScale(adj4)
for voice in voice_list:
voice_box.append_text(voice)
- voice_box.set_active(0)
+
+ try:
+ voice_index = voice_list.index(speech_config['voice'])
+ except ValueError:
+ voice_box.set_active(0)
+ else:
+ voice_box.set_active(voice_index)
volume_label = gtk.Label("Volume")
rate_label = gtk.Label("Rate")
@@ -312,6 +304,16 @@ class ListenSpell(activity.Activity):
self.config_dialog.show_all()
response = self.config_dialog.run()
+
+ if response == gtk.RESPONSE_OK:
+ self.config_dialog.destroy()
+ elif response == gtk.RESPONSE_CANCEL:
+ print "going back"
+ for k in previous_speechd_config:
+ #print k + " " + str(previous_speechd_config[k])
+ self.las.speechd_config(k, previous_speechd_config[k])
+ self.config_dialog.destroy()
+
@@ -480,7 +482,7 @@ class ListenSpell(activity.Activity):
self.pronounelem = self.las.get_word_info(self.wordid, "phnm") #get a pronounciation from the list
self.display_console("Spell...") # say the explanation if the word is ambiguous.
- if self.elem != self.pronounelem and self.use_phoneme: # determine whether to bother pronouncing a description
+ if self.use_phoneme and self.elem != self.pronounelem: # determine whether to bother pronouncing a description
self.las.say_text("Spell..." + self.pronounelem, is_phoneme = True)
else:
#print "Spell... "
@@ -530,16 +532,16 @@ class ListenSpell(activity.Activity):
################################################################
+
+ def close(self):
+ self.game_exit()
def game_exit(self):
+ self._logger.debug('Quiting Game')
self.las.exit_game()
gtk.main_quit()
- ########################Game Logic##############################
-
- ################################################################
-
-
+
def main(self):
# All PyGTK applications must have a gtk.main(). Control ends here
diff --git a/dict.db b/dict.db
index 99dc47f..c3a08e3 100755
--- a/dict.db
+++ b/dict.db
Binary files differ
diff --git a/dict.py b/dict.py
index 7a956a5..c821aa2 100755
--- a/dict.py
+++ b/dict.py
@@ -10,8 +10,6 @@ __debug = True
class Dict:
- level_1 = ()
-
def __init__(self, sqliteDB = None):
if sqliteDB == None:
@@ -35,6 +33,9 @@ class Dict:
self.cur.execute("SELECT COUNT(wordid) from las_word where length = ?", (length, ))
self.num_words = self.cur.fetchone()
return self.num_words
+
+ def exit_game(self):
+ self.conn.close()
def get_random_wordid(self, length=0, numwords = 1):
@@ -188,7 +189,8 @@ class Word:
self.cur.execute("UPDATE las_phoneme SET phoneme = " + phoneme +", is_correct = 0 where wordid = ?", (self.wordid,))
self.conn.commit()
-
+ def exit_game(self):
+ self.conn.close()
if __name__ == "__main__":
k = Dict()
num_words = k.get_num_words()
diff --git a/las.py b/las.py
index 39afbb1..1413f53 100755
--- a/las.py
+++ b/las.py
@@ -6,6 +6,7 @@ import random
import time
import speechd
import commands
+import simplejson
#import csnd
from dict import Dict
from dict import Word
@@ -51,12 +52,12 @@ class Listenspell():
self.points = 0
self.words_played = 0
self.words_correct = 0
+ self.config_file = 'ls-speechd-config'
self.path = "."
self.speechd_init = False
- 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':'',
+ 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
def load_db(self, SQLiteDB):
if self.path == ".":
@@ -65,6 +66,7 @@ class Listenspell():
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 + "/"
@@ -164,6 +166,24 @@ class Listenspell():
else:
return self.__speechd_config
+
+ def load_speechd_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)
+ simplejson.dump(speech_config, fp)
+ else:
+ speech_config = simplejson.load(fp)
+ for attr in speech_config:
+ self.speechd_config(attr, speech_config[attr])
+ fp.close()
+ return speech_config
+
+
+
def __start_speechd(self):
try:
self.client = speechd.SSIPClient('spd-test')
@@ -176,6 +196,23 @@ class Listenspell():
return False
self.speechd_init = True
+ def __set_speechd_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
+ fp = open(self.path + self.config_file, 'w', 0)
+ simplejson.dump(self.__speechd_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)
+ fp.close()
+
def speechd_config(self, attribute = None, data = None):
if attribute == None or data == None:
@@ -184,25 +221,34 @@ class Listenspell():
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()
+
+ 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)
+ if attribute == "pitch":
+ self.client.set_pitch(int(data)) #-100 to 100
+ elif attribute == "rate":
+ 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()
+ except AssertionError, e:
+ print "Assertion Error: " + str(e) + ":" + str(attribute) + ":" + str(data)
+ return False
else: return False
def __speechd_callback(self,callback_type):
@@ -237,6 +283,8 @@ class Listenspell():
return k
def exit_game(self):
+ self.word_obj.exit_game()
+ self.dict_obj.exit_game()
self.say_text("goodbye")
self.client.close()
sys.exit()
diff --git a/ls-speechd-config b/ls-speechd-config
new file mode 100644
index 0000000..079b966
--- /dev/null
+++ b/ls-speechd-config
@@ -0,0 +1 @@
+{"language": "en", "punctuation": "some", "volume": 100.0, "rate": 3.0, "pitch": -25.0, "spelling": false, "voice": "MALE1"} \ No newline at end of file