def run_saera(self, widget=None, event=None, data=None): try: coords = self.q.get_nowait() except Empty: pass else: saera_processing.location = coords print "Coords: ", coords if(event == "speech-event"): text = data[0].upper() + data[1:].lower().replace(" and nine hundred", " N900") else: text = self.input.get_text() if text: print "Got input: " + text self.lines.append([text, True]) self.input.set_text("") self.darea.queue_draw() result, func = saera_processing.parse_input(text+" ") else: result = False func = False if(settings['use_google_voice'] == 'unrecognized' and result.startswith("I don't understand ")) or settings['use_google_voice'] == 'always': print "Sending to Google..." cmd = r'wget -q -U "Mozilla/5.0" --post-file /tmp/saera/output.flac -O- '\ '--header="Content-Type: audio/x-flac; rate='+str(SAMPLE_RATE)+r'" "'\ +gv_api_url+'"' print(cmd) status, result = commands.getstatusoutput(cmd) if status: print "Google voice recognition failed." else: print "Result from google: %s" % result text = json.loads(result)['hypotheses'][0]['utterance'] print "Got back '"+text+"'" self.lines[-1][0] = text result, func = saera_processing.parse_input(text+" ") if func: eval(func) global pulsing global able_to_listen pulsing = False able_to_listen = True if result: self.lines.append([result,False]) self.lines = self.lines[-20:] self.darea.queue_draw() #Espeak makes a poor guess how to pronounce this, so we help it out. result = result.replace("maemo","maymo") result = result.replace("I am.","Ay am.") result = result.replace("sushi", "sooshi") result = result.replace("falafel", "fuh-laHfel") gobject.timeout_add(100, os.system, saera_processing.sent.espeak_cmdline+' "'+result+'"') gobject.timeout_add(500, self.check_proximity_sensor)
def run_saera(self, widget=None, event=None, data=None): if event=="speech-event": text = data[0].upper()+data[1:].lower().replace(" and nine hundred", " N900") else: text = self.input.get_text() if text: self.lines.append([text, True]) self.input.set_text("") self.darea.queue_draw() result, func = saera_processing.parse_input(text+" ") if func: eval(func) self.lines.append([result,False]) self.lines = self.lines[-20:] global pulsing pulsing = False self.darea.queue_draw() #Espeak makes a poor guess how to pronounce this, so we help it out. result = result.replace("maemo","maymo") gobject.timeout_add(100, os.system, 'espeak -v +f2 "'+result+'"')
def run_saera(self, widget=None, event=None, data=None): if event == "speech-event": text = data[0].upper() + data[1:].lower().replace( " and nine hundred", " N900") else: text = self.input.get_text() if text: self.lines.append([text, True]) self.input.set_text("") self.darea.queue_draw() result, func = saera_processing.parse_input(text + " ") if func: eval(func) self.lines.append([result, False]) self.lines = self.lines[-20:] global pulsing pulsing = False self.darea.queue_draw() #Espeak makes a poor guess how to pronounce this, so we help it out. result = result.replace("maemo", "maymo") gobject.timeout_add(100, os.system, 'espeak -v +f2 "' + result + '"')
def run_saera(self, widget=None, event=None, data=None): try: coords = self.q.get_nowait() except Empty: pass else: saera_processing.location = coords print "Coords: ", coords if event=="speech-event": text = data[0].upper()+data[1:].lower().replace(" and nine hundred", " N900") else: text = self.input.get_text() if text: print "Got input: "+text self.lines.append([text, True]) self.input.set_text("") self.darea.queue_draw() result, func = saera_processing.parse_input(text+" ") if func: eval(func) elif result.startswith("I don't understand "): if settings['use_google_voice']=="unrecognized" and event=="speech-event": print "Sending to Google..." # os.system('wget -q -U "Mozilla/5.0" --post-file /tmp/saera/output.flac' \ # + ' --header="Content-Type: audio/x-flac; rate='+str(SAMPLE_RATE)+'" -O - '+gv_api_url+' > /tmp/saera/parsed.ret') os.system(r'wget -q -U "Mozilla/5.0" --post-file /tmp/saera/output.flac '\ '--header="Content-Type: audio/x-flac; rate='+str(SAMPLE_RATE)+r'" "'\ +gv_api_url+'" -O /tmp/saera/parsed.ret && '+"cat /tmp/saera/parsed.ret | sed 's/.*utterance\":\"//' | " \ +"sed 's/\",\"confidence.*//' > /tmp/saera/result.txt") print (r'wget -q -U "Mozilla/5.0" --post-file /tmp/saera/output.flac '\ '--header="Content-Type: audio/x-flac; rate='+str(SAMPLE_RATE)+r'" -O '\ '- '+gv_api_url+' > /tmp/saera/parsed.ret && '+"cat /tmp/saera/parsed.ret | sed 's/.*utterance\":\"//' | " \ +"sed 's/\",\"confidence.*//' > /tmp/saera/result.txt") text = open('/tmp/saera/result.txt').read().strip() text = text[0].upper()+text[1:].lower().replace(" and nine hundred", " N900") self.lines[-1][0] = text print "Got back '"+text+"'" query = text.replace(" ", "_") request_url = "http://"+lang_flag+".answers.com/Q/"+query print "Sending request to answers.com..." os.system('wget "'+request_url+'" -O /tmp/saera/answer.html') answer = open('/tmp/saera/answer.html').read() if 'description' in answer: result = [i for i in answer.split('\n') if 'description' in i][0] if "content" in result: result = "".join([i for i in result.split('content="')[1].strip('"\'<>') if not i in '"<>*']) else: result = "I don't understand "+text+". Sorry" else: result = "I don't understand "+text+". Sorry." global pulsing global able_to_listen pulsing = False able_to_listen = True if result: self.lines.append([result,False]) self.lines = self.lines[-20:] self.darea.queue_draw() #Espeak makes a poor guess how to pronounce this, so we help it out. result = result.replace("maemo","maymo") result = result.replace("I am.","Ay am.") result = result.replace("sushi", "sooshi") result = result.replace("falafel", "fuh-laHfel") gobject.timeout_add(100, os.system, saera_processing.sent.espeak_cmdline+' "'+result+'"') gobject.timeout_add(500, self.check_proximity_sensor)