def task(quit_event): mic = Microphone(quit_event=quit_event) player = Player(mic.pyaudio_instance) pixel_ring.set_color(rgb=0x505000) time.sleep(3) speech = Speech() myBot = Bot() while not quit_event.is_set(): if mic.wakeup(keyword='olaf'): pixel_ring.listen() data = mic.listen() pixel_ring.wait() text = speech.recognize(data) if text: logger.debug('Recognized : %s', text) result = myBot.request(text) pixel_ring.speak(4, 0) audio = speech.synthetize(result) if (audio != None): player.play_raw(audio) pixel_ring.off() mic.close() pixel_ring.off()
def main(): import signal thread = None #if not get_refresh_token(): # thread = Thread(target=login) # thread.daemon = True # thread.start() if not get_refresh_token(): thread = Thread(target=get_token_loop) thread.daemon = True thread.start() quit_event = Event() def handler(signum, frame): quit_event.set() if thread: tornado.ioloop.IOLoop.instance().stop() signal.signal(signal.SIGINT, handler) get_refresh_token() #mosq_command='/usr/bin/mosquitto_sub -h 120.27.138.117 -t umomoSofa -v &' mosq_command = '/usr/bin/mosquitto_sub' subprocess.Popen(mosq_command, shell=True) mic_command = '/usr/bin/mic_wake' subprocess.Popen(mic_command, shell=True) mic = Microphone(quit_event=quit_event) alexa = Alexa() print("========================alexa start========================") while not quit_event.is_set(): with open('/etc/config/mic_wake') as f: contents = f.read() #if mic.wakeup(keyword='alexa'): if "1" in contents: logging.debug('wakeup') if not get_refresh_token(): if platform.machine() == 'mips': command = 'madplay -o wave:- {} | aplay -M'.format( hint_file) else: command = 'ffplay -autoexit -nodisp {}'.format(hint_file) subprocess.Popen(command, shell=True).wait() continue data = mic.listen() print( "========================alexa listen========================") try: alexa.recognize(data) except Exception as e: logging.warn(e.message) mic.close() logging.debug('Mission completed')
def main(): quit_event = Event() mic = Microphone(quit_event=quit_event) alexa = Alexa(mic) def on_quit(signum, frame): quit_event.set() signal.signal(signal.SIGINT, on_quit) right_button = Button(3) right_button.when_pressed = alexa.recognize pause() mic.close() logging.debug('Mission completed')
def main(): global mic, quit_event pa = pyaudio.PyAudio() mic = Microphone(pa) while not quit_event.is_set(): if mic.detect(keyword='alexa'): print('wakeup') data = mic.listen() data = b''.join(data) if data: alexa(data) mic.close()
def main(): import signal thread = None if not get_refresh_token(): thread = Thread(target=login) thread.daemon = True thread.start() quit_event = Event() def handler(signum, frame): quit_event.set() if thread: tornado.ioloop.IOLoop.instance().stop() signal.signal(signal.SIGINT, handler) mic = Microphone(quit_event=quit_event) alexa = Alexa() while not quit_event.is_set(): if mic.wakeup(keyword='alexa'): logging.debug('wakeup') if not get_refresh_token(): if platform.machine() == 'mips': command = 'madplay -o wave:- {} | aplay -M'.format( hint_file) else: command = 'ffplay -autoexit -nodisp {}'.format(hint_file) subprocess.Popen(command, shell=True).wait() continue data = mic.listen() try: alexa.recognize(data) except Exception as e: logging.warn(e.message) mic.close() logging.debug('Mission completed')
def main(): import signal thread = None if not get_refresh_token(): thread = Thread(target=login) thread.daemon = True thread.start() quit_event = Event() def handler(signum, frame): quit_event.set() if thread: tornado.ioloop.IOLoop.instance().stop() signal.signal(signal.SIGINT, handler) mic = Microphone(quit_event=quit_event) alexa = Alexa() while not quit_event.is_set(): if mic.wakeup(keyword='alexa'): logging.debug('wakeup') if not get_refresh_token(): if platform.machine() == 'mips': command = 'madplay -o wave:- {} | aplay -M'.format(hint_file) else: command = 'ffplay -autoexit -nodisp {}'.format(hint_file) subprocess.Popen(command, shell=True).wait() continue data = mic.listen() try: alexa.recognize(data) except Exception as e: logging.warn(e.message) mic.close() logging.debug('Mission completed')
def main(): quit_event = Event() mic = Microphone(quit_event=quit_event) alexa = Alexa(mic) def on_quit(signum, frame): quit_event.set() signal.signal(signal.SIGINT, on_quit) while not quit_event.is_set(): if mic.wakeup(keyword='alexa'): logging.debug('wakeup') data = mic.listen() try: alexa.recognize(data) except Exception as e: logging.warn(e.message) mic.close() logging.debug('Mission completed')