def select_cell(self, keyname): try: keyn = int(keyname) - 1 except ValueError: no_valid_number = _("It is not a valid number") retry = _("Try again") reporter.report_failure(no_valid_number + "." + retry + ".") return if (keyn == -1): keyn = 0 self.win.hide() keyl = keyn / 3 keyr = keyn % 3 self.position_y = self.position_y + keyl * self.size_y / 3 self.position_x = self.position_x + keyr * self.size_x / 3 self.size_x = self.size_x / 3 self.size_y = self.size_y / 3 d = display.Display() s = d.screen() root = s.root root.warp_pointer(self.position_x + self.size_x / 2, self.position_y + self.size_y / 2) d.sync() self.win.show_all() self.win.fullscreen()
def select_cell(self,keyname): try: keyn = int(keyname)- 1 except ValueError: no_valid_number = _("It is not a valid number") retry = _("Try again") reporter.report_failure(no_valid_number + "." + retry + ".") return if (keyn==-1): keyn=0 self.win.hide() keyl = keyn/3 keyr = keyn%3 self.position_y = self.position_y + keyl * self.size_y/3 self.position_x = self.position_x + keyr *self.size_x/3 self.size_x = self.size_x/3 self.size_y = self.size_y/3 d = display.Display() s = d.screen() root = s.root root.warp_pointer(self.position_x + self.size_x/2, self.position_y + self.size_y/2) d.sync() self.win.show_all() self.win.fullscreen()
def handle_response(resp): if resp =="": reporter.report_failure("Unrecognized command") else: try: hypotheses = json.loads(resp)['hypotheses'] except json.decoder.JSONDecodeError: no_response=_("No response received") behind_firewall=_("Are you behind a firewall?") reporter.report_error(no_response + "." + behind_firewall) return for index in range(len(hypotheses)): values = hypotheses[index].values() if len(values)==1: text = values[0] logging.debug( "Result \"" + text + "\" with unknown confidence" ) else: confidence, text = values logging.debug( "Result \"" + text + "\" with confidence " + str(confidence) ) retp = text_processor.process_text(text, status_icon.get_language()) if (retp==True): return;
def handle_response(resp): if resp == "": reporter.report_failure("Unrecognized command") else: try: hypotheses = json.loads(resp)['hypotheses'] except json.decoder.JSONDecodeError: no_response = _("No response received") behind_firewall = _("Are you behind a firewall?") reporter.report_error(no_response + "." + behind_firewall) return for index in range(len(hypotheses)): values = hypotheses[index].values() if len(values) == 1: text = values[0] logging.debug("Result \"" + text + "\" with unknown confidence") else: confidence, text = values logging.debug("Result \"" + text + "\" with confidence " + str(confidence)) retp = text_processor.process_text(text, status_icon.get_language()) if (retp == True): return
def process_text(self, text, lang): if len(text) == 1: if self.is_grid_running == True: if '0' <= text[:1] <= '9': #send command to grid self.grid.select_cell(text) reporter.report_success(text) return True else: self.insert_text(text, lang) return True if text == "grid" or text == "griglia": if self.grid != None and self.is_grid_running == True: self.grid.stop() if (self.grid == None): self.grid = grid.Grid() self.grid.start() self.is_grid_running = True reporter.report_success(text) return True # Ignore some token in initial position if text.startswith('open ') or text.startswith( 'run ') or text.startswith('apri '): startpos = text.find(" ") + 1 t = text[startpos:] return self.open_program(t, lang, text.split(" ")[0].strip()) # Keyword in order to go to a web page elif text.startswith('vai su ') or text.startswith('go to '): startpos = text.find(" ") + 1 t = text[startpos:] startpos = t.find(" ") + 1 t = t[startpos:] self.google_search(t) return True # Keyword in order to write with vocal keyboard elif text.startswith('scrivi ') or text.startswith('write '): startpos = text.find(" ") + 1 t = text[startpos:] self.insert_text(t, lang) return True else: status = self.open_program(text, lang, "") if self.is_grid_running == True and status == True: self.grid.stop() if (status == False): t = text if text.startswith('chi è ') or text.startswith('cosa è '): startpos = text.find("è ") + 1 t = text[startpos:] if text.startswith('who is') or text.startswith('what is'): startpos = text.find("is ") + 1 t = text[startpos:] status = self.sparql.run(t, lang[:2]) if (status == True): reporter.report_success(text) return status reporter.report_failure(text)
def process_text(self, text, lang): if len(text)==1: if self.is_grid_running == True: if '0' <= text[:1] <= '9': #send command to grid self.grid.select_cell(text) reporter.report_success(text) return True; else: self.insert_text(text, lang) return True if text == "grid" or text == "griglia": if self.grid!=None and self.is_grid_running == True: self.grid.stop() if (self.grid == None): self.grid = grid.Grid() self.grid.start() self.is_grid_running = True reporter.report_success(text) return True # Ignore some token in initial position if text.startswith('open ') or text.startswith('run ') or text.startswith('apri '): startpos = text.find(" ") + 1 t = text[startpos:] return self.open_program(t, lang, text.split(" ")[0].strip()) # Keyword in order to go to a web page elif text.startswith('vai su ') or text.startswith('go to '): startpos = text.find(" ") + 1 t = text[startpos:] startpos = t.find(" ") + 1 t = t[startpos:] self.google_search(t); return True # Keyword in order to write with vocal keyboard elif text.startswith('scrivi ') or text.startswith('write '): startpos = text.find(" ") + 1 t = text[startpos:] self.insert_text(t, lang) return True else: status = self.open_program(text, lang, "") if self.is_grid_running == True and status == True: self.grid.stop() if (status == False): t = text if text.startswith('chi è ') or text.startswith('cosa è '): startpos = text.find("è ") + 1 t = text[startpos:] if text.startswith('who is') or text.startswith('what is'): startpos = text.find("is ") + 1 t = text[startpos:] status = self.sparql.run(t, lang[:2]) if (status == True): reporter.report_success(text) return status reporter.report_failure(text)
def run_command(self, command): progname = command.split(" ")[0] if self.program_exists(progname): subprocess.Popen(command, shell=True) return True else: command_not_found = _("Command not found") reporter.report_failure(command_not_found + " " + progname + ".") return False
def screen_changed(self, widget, old_screen = None): # To check if the display supports alpha channels, get the colormap screen = widget.get_screen() colormap = screen.get_rgba_colormap() if colormap == None: noalpha = _("Your screen does not support alpha channels") reporter.report_failure(noalpha + ".") exit() # Now we have a colormap appropriate for the screen, use it widget.set_colormap(colormap) return False
def screen_changed(self, widget, old_screen=None): # To check if the display supports alpha channels, get the colormap screen = widget.get_screen() colormap = screen.get_rgba_colormap() if colormap == None: noalpha = _("Your screen does not support alpha channels") reporter.report_failure(noalpha + ".") exit() # Now we have a colormap appropriate for the screen, use it widget.set_colormap(colormap) return False
def send_recv(): audio = open(FLAC_OUTPUT_FILENAME, 'rb').read() filesize = os.path.getsize(FLAC_OUTPUT_FILENAME) HTTP_ADDRESS = 'http://www.google.com/speech-api/v1/recognize?lang=' + status_icon.get_language() + '&maxresults=' + str(MAXRESULT) req = urllib2.Request(url=HTTP_ADDRESS) req.add_header('Content-type','audio/x-flac; rate=16000') req.add_header('Content-length', str(filesize)) req.add_data(audio) try: response = urllib2.urlopen(req) return response.read() except urllib2.HTTPError, e: error_message = e.read() logging.debug(error_message.lower().split('<title>')[1].split('</title>')[0]) no_connection=_("Can't establish a connection to the server") reporter.report_failure(no_connection + ".")
def send_recv(): audio = open(FLAC_OUTPUT_FILENAME, 'rb').read() filesize = os.path.getsize(FLAC_OUTPUT_FILENAME) HTTP_ADDRESS = 'http://www.google.com/speech-api/v1/recognize?lang=' + status_icon.get_language( ) + '&maxresults=' + str(MAXRESULT) req = urllib2.Request(url=HTTP_ADDRESS) req.add_header('Content-type', 'audio/x-flac; rate=16000') req.add_header('Content-length', str(filesize)) req.add_data(audio) try: response = urllib2.urlopen(req) return response.read() except urllib2.HTTPError, e: error_message = e.read() logging.debug( error_message.lower().split('<title>')[1].split('</title>')[0]) no_connection = _("Can't establish a connection to the server") reporter.report_failure(no_connection + ".")
req.add_data(audio) try: response = urllib2.urlopen(req) return response.read() except urllib2.HTTPError, e: error_message = e.read() logging.debug(error_message.lower().split('<title>')[1].split('</title>')[0]) no_connection=_("Can't establish a connection to the server") reporter.report_failure(no_connection + ".") except urllib2.URLError, e: error_message = e.reason logging.debug(error_message) no_connection=_("Can't establish a connection to the server") reporter.report_failure(no_connection + ".") return None def get_current_volume(data): LO = 2000 HI = 32000 log_lo = math.log(LO) log_hi = math.log(HI) # transform data to logarithmic scale try: peak = audioop.max(data, 2) except: return -1
try: response = urllib2.urlopen(req) return response.read() except urllib2.HTTPError, e: error_message = e.read() logging.debug( error_message.lower().split('<title>')[1].split('</title>')[0]) no_connection = _("Can't establish a connection to the server") reporter.report_failure(no_connection + ".") except urllib2.URLError, e: error_message = e.reason logging.debug(error_message) no_connection = _("Can't establish a connection to the server") reporter.report_failure(no_connection + ".") return None def get_current_volume(data): LO = 2000 HI = 32000 log_lo = math.log(LO) log_hi = math.log(HI) # transform data to logarithmic scale try: peak = audioop.max(data, 2) except: return -1