diff options
-rwxr-xr-x | ListenSpell.py (renamed from las-gui.py) | 265 | ||||
-rwxr-xr-x | MANIFEST | 12 | ||||
-rwxr-xr-x | activity/activity-listen-spell.svg | 382 | ||||
-rwxr-xr-x | activity/activity.info | 7 | ||||
-rwxr-xr-x[-rw-r--r--] | begin.wav | bin | 30288 -> 30288 bytes | |||
-rwxr-xr-x[-rw-r--r--] | correct.wav | bin | 32186 -> 32186 bytes | |||
-rwxr-xr-x[-rw-r--r--] | dict.db | bin | 13599744 -> 13942784 bytes | |||
-rwxr-xr-x | dict.py | 30 | ||||
-rwxr-xr-x | dist/listen-spell-1.xo | bin | 0 -> 6326808 bytes | |||
-rwxr-xr-x[-rw-r--r--] | incorrect.wav | bin | 32992 -> 32992 bytes | |||
-rwxr-xr-x | las.py | 113 | ||||
-rwxr-xr-x | po/listen-spell.pot | 21 | ||||
-rwxr-xr-x | setup.py | 3 | ||||
-rwxr-xr-x | sugar-speechd | bin | 22166 -> 0 bytes |
14 files changed, 726 insertions, 107 deletions
diff --git a/las-gui.py b/ListenSpell.py index 4d833fa..68c8c80 100755 --- a/las-gui.py +++ b/ListenSpell.py @@ -1,44 +1,87 @@ #!/usr/bin/env python - - import pygtk pygtk.require('2.0') + import gtk +import os +import string from las import Listenspell +from sugar.activity import activity +from sugar.datastore import datastore +import logging +from gettext import gettext as _ -class LS_gui: - - # This is a callback function. The data arguments are ignored - # in this example. More on callbacks below. - def __init__(self, handle): - self.__init__() - - def __init__(self): +class ListenSpell(activity.Activity): + + def __init__(self, handle = None, is_stand_alone = False): + self.is_stand_alone = is_stand_alone + + if not self.is_stand_alone: + activity.Activity.__init__(self, handle) + self._name = handle + self._logger = logging.getLogger('listen-spell') + + path = __file__ + path = path.rpartition("/") + self.las = Listenspell() + self.las.set_path(path[0]) + DBname = "dict.db" + self.las.load_db(DBname) self.use_phoneme = False - self.las = Listenspell(DBname) + self.load_activity_interface() + self.las.play_sound("begin") + self.las.say_text("Welcome", wait = False) + self.ask_skill_level() self.play_game("start") gtk.main() - def destroy(self, widget, data=None): - #print "destroy signal occurred" - self.game_exit() - def load_activity_interface(self): - self.main_window = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.main_window.connect("destroy", self.destroy) - - self.main_window.set_border_width(10) - - self.main_window.set_title("Listen and Spell") + #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) + self.main_window.set_border_width(10) + 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) + + self.set_toolbox(toolbox) + toolbox.show_all() + # Set title for our Activity + + self.set_title('Listen and Spell') self.Hcontainer = gtk.HBox() self.Hcontainer.show() - - self.main_window.add(self.Hcontainer) - + + if self.is_stand_alone: + self.main_window.add(self.Hcontainer) + self.vcontainer_left = gtk.VBox() self.vcontainer_left.set_border_width(10) self.vcontainer_left.show() @@ -53,36 +96,14 @@ class LS_gui: #####################Left Pane widgets########################## - #self.label_v_left_a = gtk.Label("Hello this is label 1") - #self.label_v_left_b = gtk.Label("label 2") - - #self.label_v_left_a.show() - #self.label_v_left_b.show() - - #self.main_output_view = gtk.TextView() - #self.main_output_buffer = gtk.TextBuffer() - #self.main_output_buffer.set_text("This is main output") - #self.main_output_view.set_editable(False) - #self.main_output_view.set_buffer(self.main_output_buffer) - - #self.display_main_output("This is main output") - - #self.main_output_view.show_all() self.text_input = gtk.Entry() - #self.text_input.set_text("Preset input text") - #self.text_input. self.text_input.show() self.text_input.connect("focus-in-event", self.text_input_focus, None) self.text_input.connect("activate", self.text_input_activate, None) self.console_text_view = gtk.TextView() - - #self.console_text_view.show() - #self.h_adj = gtk.Adjustment(value=0, lower=0, upper=4, step_incr=1, page_incr=0, page_size=0) - #self.console_text_sw = gtk.ScrolledWindow(vadjustment=self.h_adj) - self.console_text_sw = gtk.ScrolledWindow() self.console_text_sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) self.console_text_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) @@ -103,9 +124,6 @@ class LS_gui: self.console_text_frame.add(self.console_text_sw) self.console_text_frame.show_all() - #self.vcontainer_left.pack_start(self.main_output_view, True, True ) - #self.vcontainer_left.pack_start(self.label_v_left_b, True, False ) - self.vcontainer_left.pack_start(self.console_text_frame, True, True ) self.vcontainer_left.pack_start(self.text_input, False, True ) self.vcontainer_left.pack_start(self.text_submit_button, False, False ) @@ -128,10 +146,17 @@ class LS_gui: self.get_word_length_button = gtk.Button("Get Word Length") self.get_word_length_button.connect("clicked", self.get_word_length_button_clicked, None) + self.change_skill_level_button = gtk.Button("Change Skill Level") + self.change_skill_level_button.connect("clicked", self.change_skill_level_button_clicked, None) + + self.change_skill_level_button = gtk.Button("Speech Configuration") + self.change_skill_level_button.connect("clicked", self.speech_configuration_button_clicked, None) + self.v_buttonbox.add(self.repeat_word_button) self.v_buttonbox.add(self.get_def_button) self.v_buttonbox.add(self.get_usage_button) self.v_buttonbox.add(self.get_word_length_button) + self.v_buttonbox.add(self.change_skill_level_button) self.v_buttonbox.show_all() @@ -174,13 +199,125 @@ class LS_gui: self.stats_frame.add(self.stats_table) self.stats_frame.show_all() + if not self.is_stand_alone: + self._logger.debug('activity loaded') ################################################################ - - self.main_window.show() + if self.is_stand_alone: + self.main_window.show() + else: + self.set_canvas(self.Hcontainer) + self.show_all() ##################Call Backs#################################### + + + def _update_configuration(self, widget, attribute ): + if attribute == "voice": + self.las.speechd_config(attribute, widget.get_active_text()) + else: + self.las.speechd_config(attribute, widget.get_value()) + + + def _speech_test(self, widget, speech_text): + 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.las.say_text("Skill Level") + #vbox = gtk.VBox(False, 8) + #Vbox.set_border_width(8) + + config_table = gtk.Table(4,2) + config_table.set_row_spacings(4) + config_table.set_col_spacings(4) + + speech_frame= gtk.Frame("Speech Configuration") + speech_frame.add(config_table) + + 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) + + + volume_hscale = gtk.HScale(volume_adj) + rate_hscale = gtk.HScale(rate_adj) + pitch_hscale = gtk.HScale(pitch_adj) + + volume_hscale.set_digits(0) + rate_hscale.set_digits(0) + pitch_hscale.set_digits(0) + + + volume_hscale.set_update_policy(gtk.UPDATE_DISCONTINUOUS) + rate_hscale.set_update_policy(gtk.UPDATE_DISCONTINUOUS) + pitch_hscale.set_update_policy(gtk.UPDATE_DISCONTINUOUS) + + voice_box = gtk.combo_box_new_text() + voice_list = ["MALE1", "MALE2", "MALE3", "FEMALE1", "FEMALE2", "FEMALE3", "CHILD_MALE", "CHILD_FEMALE"] + #hscale4 = gtk.HScale(adj4) + for voice in voice_list: + voice_box.append_text(voice) + voice_box.set_active(0) + + volume_label = gtk.Label("Volume") + rate_label = gtk.Label("Rate") + pitch_label = gtk.Label("pitch") + voice_label = gtk.Label("Voice") + + volume_adj.connect('value_changed',self._update_configuration, "volume") + rate_adj.connect('value_changed',self._update_configuration, "rate") + pitch_adj.connect('value_changed',self._update_configuration, "pitch") + voice_box.connect('changed', self._update_configuration, "voice") + + + config_table.attach(volume_label, 0,1,0,1) + config_table.attach(rate_label, 0,1,1,2) + config_table.attach(pitch_label, 0,1,2,3) + config_table.attach(voice_label, 0,1,3,4) + + config_table.attach(volume_hscale, 1,2,0,1) + config_table.attach(rate_hscale, 1,2,1,2) + config_table.attach(pitch_hscale, 1,2,2,3) + config_table.attach(voice_box, 1,2,3,4) + + + speech_test_frame = gtk.Frame("Test Speech Setting") + + self.config_dialog.vbox.pack_start(speech_test_frame, False, False, 0) + + + + speech_test_table = gtk.Table(2,1) + speech_test_table.set_row_spacings(4) + speech_test_table.set_col_spacings(4) + + speech_test_frame.add(speech_test_table) + + speech_test_text_entry = gtk.Entry() + speech_test_text_entry.set_text("The quick brown fox jumps over the lazy dog") + + speech_test_button = gtk.Button("Test") + + speech_test_button.connect("clicked", self._speech_test, speech_test_text_entry.get_text()) + + speech_test_table.attach(speech_test_text_entry, 0,1,0,1) + speech_test_table.attach(speech_test_button, 0,1,1,2) + + + + self.config_dialog.show_all() + + response = self.config_dialog.run() + + + + def get_speechd_config(self): + pass + def submit_button_clicked(self, widget, data = None): answer = self.text_input.get_text() self.las.say_text("You typed") @@ -197,6 +334,8 @@ class LS_gui: self.shout(self.elem) self.update_all() self.play_game("next word") + if not self.is_stand_alone: + self._logger.debug('submit button clicked : ' + self.elem + '') return False def text_input_focus(self, widget, event, data= None): @@ -213,12 +352,16 @@ class LS_gui: self.las.say_text(self.pronounelem, is_phoneme = True) else: self.las.say_text(self.elem) + if not self.is_stand_alone: + self._logger.debug('repeat button clicked : ' + self.elem + '') def get_def_button_clicked(self, widget, data = None): def_list = self.las.get_word_info(self.wordid, "def") self.display_console("Definition: ") for (pos, definition, name) in def_list: self.display_console(pos + "(" + name + ") : " + definition) + if not self.is_stand_alone: + self._logger.debug('get defination button clicked : ' + self.elem + '') def get_usage_button_clicked(self, widget, data = None): if self.usage_used == 0: @@ -232,12 +375,16 @@ class LS_gui: (sample) = usage[self.usage_used] las.say_text(sample) self.usage_used = self.usage_used + 1 + if not self.is_stand_alone: + self._logger.debug('get usage button clicked : ' + self.elem + '') def get_word_length_button_clicked(self, widget, data = None): self.display_console("Word Length: " + str(len(self.elem))) + if not self.is_stand_alone: + self._logger.debug('get word length button clicked : ' + self.elem + '') def ask_skill_level(self): - self.skill_level_dialog = gtk.Dialog("Enter Skill Level", self.main_window, 0,(gtk.STOCK_OK, gtk.RESPONSE_OK, "Quit Game", gtk.RESPONSE_CANCEL)) + self.skill_level_dialog = gtk.Dialog("Enter Skill Level", self, 0,(gtk.STOCK_OK, gtk.RESPONSE_OK, "Quit Game", gtk.RESPONSE_CANCEL)) self.las.say_text("Skill Level") hbox = gtk.HBox(False, 8) hbox.set_border_width(8) @@ -262,10 +409,11 @@ class LS_gui: if response == gtk.RESPONSE_OK: skill_level = int (local_skill_level.get_text()) + if not self.is_stand_alone: + self._logger.debug('level set : ' + str(skill_level) + '') self.skill_level_dialog.destroy() self.las.set_skill_level(skill_level) self.update_all() - elif response == gtk.RESPONSE_CANCEL: self.game_exit() elif response == gtk.RESPONSE_NONE: @@ -278,6 +426,11 @@ class LS_gui: def local_skill_level_activate(self, widget, data=None): self.skill_level_dialog.response(gtk.RESPONSE_OK) + + def change_skill_level_button_clicked(self, widget, data=None): + self.ask_skill_level() + self.play_game("start") + def shout(self,string): self.display_console("") for char in string: @@ -335,12 +488,8 @@ class LS_gui: def play_game(self,mode = "start"): if mode == "start": - self.las.play_sound("begin") self.this_level_size = 7 self.this_level_max_error = 3 - #self.display_main_output("Welcome") - self.las.say_text("Welcome", wait = False) - self.ask_skill_level() self.wordid_list = self.las.load_wordid(self.this_level_size + self.this_level_max_error) self.this_level_num_words = len(self.wordid_list) self.this_level_words_left = self.this_level_num_words @@ -400,7 +549,7 @@ class LS_gui: # If the program is run directly or passed as an argument to the python # interpreter then create a HelloWorld instance and show it if __name__ == "__main__": - gui = LS_gui() + gui = ListenSpell(is_stand_alone = True) #gui.__init__() #gui.play_game("start") #gui.main() diff --git a/MANIFEST b/MANIFEST new file mode 100755 index 0000000..f1a29c8 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,12 @@ +activity/activity.info +activity/activity-listen-spell.svg +dict.db +correct.wav +ls.py +setup.py +dict.py +conv.sh +incorrect.wav +begin.wav +las.py +ListenSpell.py diff --git a/activity/activity-listen-spell.svg b/activity/activity-listen-spell.svg new file mode 100755 index 0000000..8d259ab --- /dev/null +++ b/activity/activity-listen-spell.svg @@ -0,0 +1,382 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" +"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> +<!-- Created with Inkscape (http://www.inkscape.org/) --> +<svg + version="1.0" + x="0.0000000" + y="0.0000000" + width="60.000000" + height="60.000000" + id="svg1" + sodipodi:version="0.32" + inkscape:version="0.40" + sodipodi:docname="matlab.svg" + sodipodi:docbase="/home/scaba" + xmlns="http://www.w3.org/2000/svg" + xmlns:cc="http://web.resource.org/cc/" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:xlink="http://www.w3.org/1999/xlink"> + <metadata + id="metadata28"> + <rdf:RDF + id="RDF29"> + <cc:Work + rdf:about="" + id="Work30"> + <dc:format + id="format31">image/svg+xml</dc:format> + <dc:type + id="type33" + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> + </metadata> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="5.6568542" + inkscape:cx="35.948122" + inkscape:cy="22.298917" + inkscape:window-width="812" + inkscape:window-height="657" + inkscape:window-x="115" + inkscape:window-y="26" + inkscape:current-layer="svg1" + borderlayer="top" /> + <defs + id="defs3"> + <linearGradient + id="linearGradient1708"> + <stop + style="stop-color:#ffffff;stop-opacity:1.0000000;" + offset="0.0000000" + id="stop1709" /> + <stop + style="stop-color:#d9cce6;stop-opacity:1.0000000;" + offset="1.0000000" + id="stop1710" /> + </linearGradient> + <linearGradient + id="linearGradient584"> + <stop + style="stop-color:#ffffff;stop-opacity:1.0000000;" + offset="0.0000000" + id="stop585" /> + <stop + style="stop-color:#ffffff;stop-opacity:0.0000000;" + offset="1.0000000" + id="stop586" /> + </linearGradient> + <linearGradient + id="linearGradient578"> + <stop + style="stop-color:#d9cce6;stop-opacity:1.0000000;" + offset="0.0000000" + id="stop579" /> + <stop + style="stop-color:#73667f;stop-opacity:1.0000000;" + offset="1.0000000" + id="stop580" /> + </linearGradient> + <linearGradient + x1="11.889954" + y1="17.899555" + x2="47.707611" + y2="53.933167" + id="linearGradient581" + xlink:href="#linearGradient584" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.087700,0.000000,0.000000,0.919371,66.35103,-1.329236)" /> + <linearGradient + x1="14.901803" + y1="12.416366" + x2="27.636885" + y2="24.581890" + id="linearGradient583" + xlink:href="#linearGradient584" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.682464,0.000000,0.000000,0.594366,66.35103,-1.329236)" /> + <linearGradient + x1="11.050006" + y1="4.8899484" + x2="34.399300" + y2="26.972225" + id="linearGradient860" + xlink:href="#linearGradient584" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.544211,0.000000,0.000000,1.837523,66.35103,-1.329236)" /> + <linearGradient + x1="9.5028210" + y1="14.326502" + x2="53.603920" + y2="56.968639" + id="linearGradient861" + xlink:href="#linearGradient578" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.067200,0.000000,0.000000,0.937032,66.35103,-1.329236)" /> + <linearGradient + x1="3.2789278" + y1="4.5549574" + x2="54.547245" + y2="55.028416" + id="linearGradient862" + xlink:href="#linearGradient578" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.014478,0.000000,0.000000,0.985729,66.35103,-1.329236)" /> + <linearGradient + x1="1.6300739" + y1="17.134445" + x2="23.789167" + y2="39.286045" + id="linearGradient1715" + xlink:href="#linearGradient584" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.905665,0.000000,0.000000,1.104161,0.110770,-0.996927)" /> + <linearGradient + x1="1.6300739" + y1="17.134445" + x2="23.789167" + y2="39.286045" + id="linearGradient1718" + xlink:href="#linearGradient584" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.905665,0.000000,0.000000,1.104161,16.09532,-8.614897)" /> + <linearGradient + x1="1.6300739" + y1="17.134445" + x2="23.789167" + y2="39.286045" + id="linearGradient1721" + xlink:href="#linearGradient584" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.905665,0.000000,0.000000,1.104161,8.119905,-17.91955)" /> + <linearGradient + x1="6.4574761" + y1="4.6498289" + x2="25.565939" + y2="25.086603" + id="linearGradient3038" + xlink:href="#linearGradient578" + gradientUnits="userSpaceOnUse" + gradientTransform="scale(1.001030,0.998971)" /> + <linearGradient + x1="6.4574761" + y1="4.6498289" + x2="25.565939" + y2="25.086603" + id="linearGradient3039" + xlink:href="#linearGradient578" + gradientUnits="userSpaceOnUse" + gradientTransform="scale(1.001030,0.998971)" /> + <linearGradient + x1="6.4574761" + y1="4.6498289" + x2="25.565939" + y2="25.086603" + id="linearGradient3040" + xlink:href="#linearGradient578" + gradientUnits="userSpaceOnUse" + gradientTransform="scale(1.001030,0.998971)" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient1708" + id="linearGradient1711" + gradientTransform="matrix(1.003804,0.000000,0.000000,0.996210,1.439567,66.93986)" + x1="10.786067" + y1="7.1828723" + x2="27.083527" + y2="25.066830" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient578" + id="linearGradient1720" + gradientTransform="matrix(0.871647,0.000000,0.000000,1.147253,1.439567,66.93986)" + x1="19.457455" + y1="20.837318" + x2="50.554337" + y2="17.274693" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient584" + id="linearGradient1729" + gradientTransform="matrix(0.877053,0.000000,0.000000,1.140182,1.439567,66.93986)" + x1="26.271854" + y1="22.911760" + x2="46.103157" + y2="28.879768" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient584" + id="linearGradient1731" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.003804,0.000000,0.000000,0.996210,1.439567,66.93986)" + x1="17.726391" + y1="15.945027" + x2="29.533092" + y2="25.974466" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient578" + id="linearGradient1774" + gradientTransform="matrix(0.882099,0.000000,0.000000,1.133659,-71.79839,-1.439567)" + x1="124.55768" + y1="26.392714" + x2="144.69109" + y2="26.551777" + gradientUnits="userSpaceOnUse" + spreadMethod="reflect" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient578" + id="linearGradient1778" + gradientTransform="scale(1.002668,0.997339)" + x1="18.683064" + y1="20.449495" + x2="28.324802" + y2="27.445408" + gradientUnits="userSpaceOnUse" + spreadMethod="reflect" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient584" + id="linearGradient1782" + gradientTransform="matrix(1.182522,0.000000,0.000000,0.845650,-71.79839,-1.439567)" + x1="63.210545" + y1="45.250092" + x2="81.030518" + y2="36.660873" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient584" + id="linearGradient1801" + gradientTransform="scale(0.490068,2.040534)" + x1="72.493027" + y1="3.8504148" + x2="82.074326" + y2="11.770768" + gradientUnits="userSpaceOnUse" + spreadMethod="pad" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient584" + id="linearGradient1806" + gradientTransform="scale(0.831082,1.203251)" + x1="32.070965" + y1="43.514565" + x2="33.129238" + y2="35.911697" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient578" + id="linearGradient1106" + gradientUnits="userSpaceOnUse" + gradientTransform="scale(1.002668,0.997339)" + spreadMethod="reflect" + x1="18.683064" + y1="20.449495" + x2="28.324802" + y2="27.445408" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient578" + id="linearGradient1107" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.882099,0.000000,0.000000,1.133659,-71.79839,-1.439567)" + spreadMethod="reflect" + x1="124.55768" + y1="26.392714" + x2="144.69109" + y2="26.551777" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient584" + id="linearGradient1108" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.182522,0.000000,0.000000,0.845650,-71.79839,-1.439567)" + x1="63.210545" + y1="45.250092" + x2="81.030518" + y2="36.660873" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient584" + id="linearGradient1109" + gradientUnits="userSpaceOnUse" + gradientTransform="scale(0.490068,2.040534)" + spreadMethod="pad" + x1="72.493027" + y1="3.8504148" + x2="82.074326" + y2="11.770768" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient584" + id="linearGradient1110" + gradientUnits="userSpaceOnUse" + gradientTransform="scale(0.831082,1.203251)" + x1="32.070965" + y1="43.514565" + x2="33.129238" + y2="35.911697" /> + </defs> + <path + style="opacity:0.29999998;fill:#000000;fill-opacity:1.0000000;fill-rule:evenodd;stroke:none;stroke-width:1.8750000;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;" + d="M 41.918721,7.4461201 C 41.364841,7.3822571 40.350531,8.3046391 40.262471,8.4148701 C 34.846741,15.194356 31.380921,21.509085 25.731219,22.696120 C 22.512869,23.372314 24.213279,25.786854 20.699969,27.758620 C 15.946879,30.426180 9.5053892,32.997908 5.4812192,34.321120 C 4.7452992,34.563098 11.344369,40.822608 15.668719,42.789870 C 19.104839,44.353051 18.607649,41.009897 20.918719,42.008620 C 22.708899,44.012950 26.209579,47.561023 28.606211,55.289870 C 29.466781,57.181478 32.425471,55.229213 34.074971,53.039870 C 37.097941,49.501902 43.713681,41.839557 47.762471,40.789870 C 51.811251,39.740186 61.270131,49.995724 59.012471,45.383620 C 53.249711,33.611045 47.142101,10.367713 43.606221,8.1336201 C 43.098221,7.8126491 42.472601,7.5099831 41.918721,7.4461201 z " + id="path1790" + sodipodi:nodetypes="ccccccccccccc" + transform="matrix(1.021200,0.000000,0.000000,1.021200,-0.615171,-1.094169)" /> + <path + style="fill:url(#linearGradient1106);fill-opacity:1.0000000;fill-rule:evenodd;stroke:none;stroke-width:0.50000000;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;" + d="M 1.9335562,32.675217 C 1.1976442,32.917196 7.7858162,39.186800 12.110162,41.154062 C 15.546282,42.717247 15.045123,39.361461 17.356194,40.360184 C 19.716971,41.380387 27.290274,32.728116 31.814301,23.813455 C 36.338331,14.898793 37.543161,5.7217411 36.704121,6.7720561 C 31.288381,13.551541 27.841414,19.855024 22.191705,21.042059 C 18.973351,21.718253 20.677827,24.133214 17.164517,26.104980 C 12.411440,28.772538 5.9577342,31.352005 1.9335562,32.675217 z " + id="path1757" + sodipodi:nodetypes="csssssss" + transform="matrix(1.021200,0.000000,0.000000,1.021200,-0.615171,-1.094169)" /> + <path + style="fill:url(#linearGradient1107);fill-opacity:1.0000000;fill-rule:evenodd;stroke:none;stroke-width:1.8750000;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;" + d="M 37.103931,6.5394041 C 37.577011,5.2939381 39.048001,5.8511541 40.064001,6.4930941 C 43.599871,8.7271871 49.686611,31.969311 55.449371,43.741886 C 57.707031,48.353992 48.251531,38.103584 44.202751,39.153268 C 40.153971,40.202952 33.549831,47.851619 30.526861,51.389587 C 28.877361,53.578928 25.914523,55.540658 25.053950,53.649050 C 22.657320,45.920206 17.709226,40.689487 18.457701,40.322915 C 21.276240,36.322143 28.759661,28.506955 37.103931,6.5394041 z " + id="path1758" + sodipodi:nodetypes="csszcccc" + transform="matrix(1.021200,0.000000,0.000000,1.021200,-0.615171,-1.094169)" /> + <path + style="fill:none;fill-opacity:1.00000000;fill-rule:evenodd;stroke:#000000;stroke-width:0.25000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;" + d="M 2.1285872,32.730522 L 2.1285872,32.730522 z " + id="path1768" + transform="matrix(1.021200,0.000000,0.000000,1.021200,-0.615171,-1.094169)" /> + <path + style="fill:url(#linearGradient1108);fill-opacity:1.0000000;fill-rule:evenodd;stroke:none;stroke-width:0.25000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;" + d="M 16.564976,26.591147 C 17.261272,26.248838 22.843650,30.469750 24.434305,31.330872 C 24.744531,31.498817 20.024946,37.608617 17.719348,39.873138 C 15.413749,42.137658 15.522137,40.556899 14.238307,41.593725 C 13.451471,42.229178 1.5596352,35.033490 2.2185602,32.857763 C 2.3251962,32.505657 13.461035,28.117088 16.564976,26.591147 z " + id="path1769" + sodipodi:nodetypes="csssss" + transform="matrix(1.021200,0.000000,0.000000,1.021200,-0.615171,-1.094169)" /> + <path + style="fill:none;fill-opacity:1.0000000;fill-rule:evenodd;stroke:#261933;stroke-width:1.8750000;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;" + d="M 38.034911,5.7839351 C 37.481031,5.7200721 36.466721,6.6424541 36.378661,6.7526851 C 30.962931,13.532171 27.497119,19.846900 21.847409,21.033935 C 18.629059,21.710129 20.329469,24.124669 16.816159,26.096435 C 12.063069,28.763995 5.6215872,31.335723 1.5974092,32.658935 C 0.86149320,32.900913 7.4605592,39.160423 11.784909,41.127685 C 15.221029,42.690866 14.723839,39.347712 17.034909,40.346435 C 18.825089,42.350765 22.325779,45.898838 24.722409,53.627685 C 25.582979,55.519293 28.541661,53.567028 30.191161,51.377685 C 33.214131,47.839717 39.829871,40.177372 43.878661,39.127685 C 47.927441,38.078001 57.386321,48.333539 55.128661,43.721435 C 49.365901,31.948860 43.258291,8.7055281 39.722411,6.4714351 C 39.214411,6.1504641 38.588791,5.8477981 38.034911,5.7839351 z " + id="path1783" + sodipodi:nodetypes="ccccccccccccc" + transform="matrix(1.021200,0.000000,0.000000,1.021200,-0.615171,-1.094169)" /> + <path + style="fill:url(#linearGradient1109);fill-opacity:1.0000000;fill-rule:evenodd;stroke:none;stroke-width:0.25000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;" + d="M 38.006989,7.8508748 C 36.602792,8.6846170 35.322408,12.309863 35.355339,16.689710 C 35.396065,22.106239 37.609749,24.611214 38.669902,23.981748 C 39.966771,23.211732 40.267548,21.242959 40.216699,14.480000 C 40.193891,11.446584 38.959815,7.2851346 38.006989,7.8508748 z " + id="path1796" + sodipodi:nodetypes="cssss" + transform="matrix(1.021200,0.000000,0.000000,1.021200,-0.615171,-1.094169)" /> + <path + style="fill:url(#linearGradient1110);fill-opacity:1.0000000;fill-rule:evenodd;stroke:none;stroke-width:0.25000000pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000;" + d="M 22.393883,45.438131 C 22.412622,46.378282 25.296261,53.294529 25.802275,53.317257 C 26.413351,53.344704 31.632701,49.846719 31.884526,47.453677 C 32.084027,45.557856 30.015653,43.325913 28.748422,43.092476 C 27.216689,42.810315 22.338775,42.673294 22.393883,45.438131 z " + id="path1802" + sodipodi:nodetypes="cssss" + transform="matrix(1.021200,0.000000,0.000000,1.021200,-0.615171,-1.094169)" /> +</svg> diff --git a/activity/activity.info b/activity/activity.info new file mode 100755 index 0000000..b108201 --- /dev/null +++ b/activity/activity.info @@ -0,0 +1,7 @@ +[Activity] +name = listen-spell +service_name = org.laptop.listen-spell +class = ListenSpell.ListenSpell +icon = activity-listen-spell +activity_version = 1 +show_launcher = yes diff --git a/begin.wav b/begin.wav Binary files differindex be6ba53..be6ba53 100644..100755 --- a/begin.wav +++ b/begin.wav diff --git a/correct.wav b/correct.wav Binary files differBinary files differindex cb5d6bb..cb5d6bb 100644..100755 --- a/correct.wav +++ b/correct.wav @@ -9,6 +9,8 @@ __debug = True class Dict: + + level_1 = () def __init__(self, sqliteDB = None): @@ -52,6 +54,10 @@ class Dict: def get_DB_name(self): return + def level_map(self, level): + level_1 = { 3:{s:30000000000, e:1460000000 }, 4:{s:23, e:312} } + pass + class Word: def __init__(self, identifier=None, value= None): @@ -75,16 +81,18 @@ class Word: self.wordid = None self.word = None self.length = None + self.freq = None self.synsetid_list = [] return None else: return "Invalid Usage" - (laswid, wordid, lemma, length) = self.cur.fetchone() + (laswid, wordid, lemma, length, freq) = self.cur.fetchone() self.las_word_id = laswid self.wordid = wordid self.word = lemma self.length = length + self.freq = freq self.synsetid_list = [] def get_word(self): @@ -107,6 +115,8 @@ class Word: return self.synsetid_list + def get_freq(self): + return self.freq def get_def(self): self.def_list = [] if self.synsetid_list == []: @@ -160,17 +170,23 @@ class Word: else:return None def update_phoneme(self, phoneme, is_correct = True): - #print phoneme + #try: + #if is_correct == True: + #self.cur.execute("UPDATE las_phoneme SET phoneme = ?, is_correct = ? where wordid = ?", (phoneme, 1, self.wordid,)) + #else: + #self.cur.execute("UPDATE las_phoneme SET phoneme = ?, is_correct = ? where wordid = ?", (phoneme, 0, self.wordid,)) + #except: try: if is_correct == True: - self.cur.execute("UPDATE las_phoneme SET phoneme = ?, is_correct = ? where wordid = ?", (phoneme, 1, self.wordid,)) - else: - self.cur.execute("UPDATE las_phoneme SET phoneme = ?, is_correct = ? where wordid = ?", (phoneme, 0, self.wordid,)) - except: - if is_correct == True: self.cur.execute("INSERT into las_phoneme (wordid, phoneme, is_correct ) VALUES (?,?,?) ", (self.wordid, phoneme, 1, )) else: self.cur.execute("INSERT into las_phoneme (wordid, phoneme, is_correct ) VALUES (?,?,?) ", (self.wordid, phoneme, 0, )) + except sqlite3.OperationalError: + if is_correct == True: + self.cur.execute("UPDATE las_phoneme SET phoneme = " + phoneme + ", is_correct = 1 where wordid = ?", (self.wordid,)) + else: + self.cur.execute("UPDATE las_phoneme SET phoneme = " + phoneme +", is_correct = 0 where wordid = ?", (self.wordid,)) + self.conn.commit() if __name__ == "__main__": diff --git a/dist/listen-spell-1.xo b/dist/listen-spell-1.xo Binary files differnew file mode 100755 index 0000000..a2cbd8f --- /dev/null +++ b/dist/listen-spell-1.xo diff --git a/incorrect.wav b/incorrect.wav Binary files differindex 359f147..359f147 100644..100755 --- a/incorrect.wav +++ b/incorrect.wav @@ -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: diff --git a/po/listen-spell.pot b/po/listen-spell.pot new file mode 100755 index 0000000..2aaba6e --- /dev/null +++ b/po/listen-spell.pot @@ -0,0 +1,21 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2008-07-29 14:59+0530\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: activity/activity.info:2 +msgid "listen-spell" +msgstr "" diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..6c8bbb8 --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +#!/usr/bin/python +from sugar.activity import bundlebuilder +bundlebuilder.start('listen-spell') diff --git a/sugar-speechd b/sugar-speechd Binary files differdeleted file mode 100755 index c5f271a..0000000 --- a/sugar-speechd +++ /dev/null |