def getParaula(self): self.updateStatus('Parlar') if self.playing == True: if self.spoticanso: self.spoticanso.pause() os.system("/home/pi/AleixDomo/Musica/dbuscontrol.sh pause") os.system("mpg123 /home/pi/AleixDomo/Beep/On.mp3 > /dev/null 2>&1 ") audio = self.obtenirAudioRAW(True) os.system("mpg123 /home/pi/AleixDomo/Beep/Off.mp3 > /dev/null 2>&1 ") self.updateStatus(False) if self.playing == True: if self.spoticanso: self.updateStatus(True) self.spoticanso.resume() os.system("/home/pi/AleixDomo/Musica/dbuscontrol.sh pause") file = open('/home/pi/AleixDomo/txt/idioma.txt', 'r') lang = file.read() file.close() url = 'https://www.google.com/speech-api/v2/recognize?output=json&lang=' + lang + '&key=AIzaSyBE3mF21iLRYxHUgwtkC3YI9V8x3RjseFE' headers = {'Content-Type': 'audio/l16; rate=16000;', 'User-Agent':'Mozilla/5.0'} r = requests.post(url, data=audio, headers=headers).text try: final_result = r.split('[{"transcript":"')[1].split('"')[0] final_result = final_result.lower() # ho fa tot minuscules final_result = unicodedata.normalize('NFKD', final_result).encode('ASCII', 'ignore') # li treu els accents i ho guarda com a ASCII self.missatge = final_result self.missatgeready.set() self.missatgeready.clear() except: contestarVeu("No te he entendido, prueba otra vez.")
def run(self): os.system('sudo sh -c "TERM=linux setterm -foreground black -clear >/dev/tty0"') chunk = 2048 volumeThreshold = 9500 missatge = "Buenos Dias! soy Iris, pero tambiƩn me puedes llamar Pi." contestarVeu(missatge) while True: os.system('sudo sh -c "TERM=linux setterm -foreground black -clear >/dev/tty0"') if not self.playing: if self.checkKeyword(): self.getParaula() else: time.sleep(1) botostatus = self.db['BotoStatus'].find_one()['status'] if botostatus: self.db['BotoStatus'].update({'id': None}, {'status': False}, upsert=True) self.getParaula() time.sleep(0.5)