def run(self): """ Listen for input, match the modules and respond """ while True: if self.quit_flag: break try: if settings.USE_STT: stt.listen_keyword() text = stt.active_listen() else: text = input('> ') if not text: print('\n~ No text input received.\n') continue self.match_mods(text) self.execute_mods(text) except OSError as e: if 'Invalid input device' in str(e): tts.speak(settings.NO_MIC) settings.USE_STT = False continue else: raise Exception except EOFError: print('\n\n~ Shutting down...') break except: if self.error(): print(traceback.format_exc()) else: break print('\n~ Arrivederci.')
def run(self): """ Listen for input, match the modules and respond """ while True: if self.quit_flag: break try: if settings.USE_STT: stt.listen_keyword() text = stt.active_listen() else: text = eval(input('> ')) if not text: log.info('No text input received.') continue self.match_mods(text) self.execute_mods(text) except OSError as e: if 'Invalid input device' in str(e): log.error(settings.NO_MIC + '\n') settings.USE_STT = False continue else: raise Exception except (EOFError, KeyboardInterrupt): log.info('Shutting down...') break except: log.error("(runtime error)") self.error() log.info('Arrivederci.')
from athena import settings print('---- Running Microphone Test ----') try: print('\n~ Importing stt.py...') import athena.stt as stt print('~ Initializing stt.py...') stt.init() text = '' while 'q' not in text.lower(): print('\n~ Type \'q\' at any time to quit') text = input('~ Test Active or Passive Listening? (A/P): ') if 'p' in text.lower(): print('\n~ Wake Up Word: \''+settings.WAKE_UP_WORD+'\'') stt.listen_keyword() print('~ Wake Up Word Detected!') elif 'a' in text.lower(): stt.active_listen() print('\nMicrophone Test PASSED! :)\n') except Exception as e: print(traceback.format_exc()) if 'invalid input device' in str(e).lower(): print('\n~ PyAudio could not detect a microphone!') print('~ Try using a USB microphone and connecting it to different ports.') print('~ The test must be started with the microphone ALREADY plugged in.\n') else: print('\n~ Microphone Test failed :(\n')
print('\n~ Importing stt.py...') import athena.stt as stt print('~ Initializing stt.py...') stt.init() tts.init() text = '' while 'q' not in text.lower(): print('\n~ Type \'q\' at any time to quit') text = eval(input('~ Test Active or Passive Listening? (A/P): ')) if 'p' in text.lower(): print(('\n~ Wake Up Word: \'' + settings.WAKE_UP_WORD + '\'')) stt.listen_keyword() print('~ Wake Up Word Detected!') elif 'a' in text.lower(): text = stt.active_listen() print(("~ Text received: " + text)) print('\nMicrophone Test PASSED! :)\n') except Exception as e: print((traceback.format_exc())) if 'invalid input device' in str(e).lower(): print('\n~ PyAudio could not detect a microphone!') print( '~ Try using a USB microphone and connecting it to different ports.' ) print( '~ The test must be started with the microphone ALREADY plugged in.\n' ) else: print('\n~ Microphone Test failed :(\n')