import sys import logging from config import Config _HOTWORD_COUNT = False def _hotword_interrupt(): return _HOTWORD_COUNT > 1 def _hotword_callback(): logging.info('Hotword callback called.') global _HOTWORD_COUNT _HOTWORD_COUNT += 1 def _test_hotword_detection(): logging.info('Launching hotword detector...') import snowboy.snowboydecoder detector = snowboy.snowboydecoder.HotwordDetector(Config.SNOWBOY_HOTWORD_MODEL, sensitivity=0.5) detector.start(detected_callback=_hotword_callback, interrupt_check=_hotword_interrupt) def _test_audio_in(): import speech_recognition as sr with sr.Microphone() as source: recognizer = sr.Recognizer() recognizer.energy_threshold = 2000 recognizer.listen(source) def _test_audio_out(): import output.audio_output logging.info('Creating audio output service...') service = output.audio_output.AudioOutput() logging.info('Calling .success()...') service.success() logging.info('Calling .failure()...') service.failure() logging.info('Calling .tts("Hello World")...') service.tts('Hello World') logging.info('Done.') def run(): if len(sys.argv) == 1: print '\n'.join([ '1. Audio output', '2. Audio input', '3. Hotword detection', ]) return choice = sys.argv[1] if choice == '1': _test_audio_out() elif choice == '2': _test_audio_in() elif choice == '3': _test_hotword_detection() if __name__ == "__main__": logging.basicConfig(stream=sys.stdout) logging.getLogger().setLevel(logging.DEBUG) run()