def setUp(self): self.loop = RecognizerLoop() self.queue = Queue() self.recognizer = MockRecognizer() self.consumer = AudioConsumer(self.loop.state, self.queue, self.loop, MycroftSTT(), self.loop.wakeup_recognizer, self.loop.wakeword_recognizer)
def setUp(self): with patch('mycroft.configuration.Configuration.get') as \ mock_config_get: conf = base_config() conf['hotwords']['hey mycroft']['module'] = 'pocketsphinx' mock_config_get.return_value = conf rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_wake_word_recognizer(rl)
def setUp(self): self.loop = RecognizerLoop() self.queue = Queue() self.recognizer = MockRecognizer() self.consumer = AudioConsumer( self.loop.state, self.queue, self.loop, MycroftSTT(), LocalRecognizer(self.loop.wakeup_recognizer.key_phrase, self.loop.wakeup_recognizer.phonemes, "1e-16"), self.loop.mycroft_recognizer)
def setUp(self): self.loop = RecognizerLoop() self.queue = Queue() self.recognizer = MockRecognizer() self.consumer = AudioConsumer( self.loop.state, self.queue, self.loop, self.loop.wakeup_recognizer, self.loop.mycroft_recognizer, RemoteRecognizerWrapperFactory.wrap_recognizer( self.recognizer, 'google'))
def testRecognizer(self, mock_config_get): test_config = { "opt_in": False, "lang": 'en-us', "listener": { "sample_rate": 16000, "channels": 1, "record_wake_words": False, "record_utterances": False, "wake_word_upload": { "enable": False, "server": "mycroft.wickedbroadband.com", "port": 1776, "user": "******", "folder": "/home/precise/wakewords" }, "phoneme_duration": 120, "multiplier": 1.0, "energy_ratio": 1.5, "wake_word": "hey mycroft", "phonemes": "HH EY . M AY K R AO F T", "threshold": 1e-90, "stand_up_word": "wake up" }, "hotwords": { "hey mycroft": { "module": "pocketsphinx", "phonemes": "HH EY . M AY K R AO F T", "threshold": 1e-90 }, "wake up": { "module": "pocketsphinx", "phonemes": "W EY K . AH P", "threshold": 1e-20 } } } mock_config_get.return_value = test_config # Test "Hey Mycroft" rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey mycroft") # Test "Hey Victoria" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'HH EY . V IH K T AO R IY AH' rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey victoria") # Test Invalid" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'ZZZZZZZZZZZZ' rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey mycroft")
def setUp(self): self.loop = RecognizerLoop() self.queue = Queue() self.recognizer = MockRecognizer() self.consumer = AudioConsumer( self.loop.state, self.queue, self.loop, LocalRecognizer(self.loop.wakeup_recognizer.key_phrase, self.loop.wakeup_recognizer.phonemes, "1e-16"), self.loop.mycroft_recognizer, RemoteRecognizerWrapperFactory.wrap_recognizer( self.recognizer, 'google'))
def __init__(self, samp_rate): print # Pad debug messages self.ww_recognizer = RecognizerLoop.create_mycroft_recognizer( samp_rate, 'en-us') self.listener = ResponsiveRecognizer(self.ww_recognizer) print speech_logger.setLevel(100) # Disables logging to clean output
def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping, watchdog=lambda: None): global bus global loop global config try: reset_sigint_handler() PIDLock("voice") config = Configuration.get() bus = start_message_bus_client("VOICE") connect_bus_events(bus) callbacks = StatusCallbackMap(on_ready=ready_hook, on_error=error_hook, on_stopping=stopping_hook) status = ProcessStatus('speech', bus, callbacks) # Register handlers on internal RecognizerLoop bus loop = RecognizerLoop(watchdog) connect_loop_events(loop) create_daemon(loop.run) status.set_started() except Exception as e: error_hook(e) else: status.set_ready() wait_for_exit_signal() status.set_stopping()
def __init__(self, samp_rate): print # Pad debug messages self.ww_recognizer = RecognizerLoop().create_mycroft_recognizer( samp_rate, 'en-us') self.listener = ResponsiveRecognizer(self.ww_recognizer) print speech_logger.setLevel(100) # Disables logging to clean output
def setUp(self): with mock.patch('mycroft.configuration.Configuration.get') as \ mock_config_get: conf = base_config() conf['hotwords']['hey mycroft']['module'] = 'pocketsphinx' mock_config_get.return_value = conf rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_wake_word_recognizer(rl)
def setUp(self): self.loop = RecognizerLoop() self.queue = Queue() self.recognizer = MockRecognizer() self.consumer = AudioConsumer( self.loop.state, self.queue, self.loop, MycroftSTT(), self.loop.wakeup_recognizer, self.loop.wakeword_recognizer)
def testRecognitionFallback(self, mock_config_get): """If language config doesn't exist set default (english)""" conf = base_config() conf['hotwords']['hey mycroft'] = { 'lang': 'DOES NOT EXIST', 'module': 'pocketsphinx', 'phonemes': 'HH EY . M AY K R AO F T', 'threshold': 1e-90 } conf['lang'] = 'DOES NOT EXIST' mock_config_get.return_value = conf rl = RecognizerLoop() ps_hotword = RecognizerLoop.create_wake_word_recognizer(rl) expected = 'en-us' res = ps_hotword.decoder.get_config().get_string('-hmm') self.assertEqual(expected, res.split('/')[-2]) self.assertEqual('does not exist', ps_hotword.lang)
def testRecognizer(self, mock_config_get): test_config = base_config() mock_config_get.return_value = test_config # Test "Hey Mycroft" rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey mycroft") # Test "Hey Victoria" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'HH EY . V IH K T AO R IY AH' rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey victoria") # Test Invalid" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'ZZZZZZZZZZZZ' rl = RecognizerLoop() self.assertEquals(rl.wakeword_recognizer.key_phrase, "hey mycroft")
def setUp(self): with mock.patch('mycroft.configuration.Configuration.get') as \ mock_config_get: test_config = { "opt_in": False, "lang": 'en-us', "listener": { "sample_rate": 16000, "channels": 1, "record_wake_words": False, "record_utterances": False, "wake_word_upload": { "enable": False, "server": "mycroft.wickedbroadband.com", "port": 1776, "user": "******", "folder": "/home/precise/wakewords" }, "phoneme_duration": 120, "multiplier": 1.0, "energy_ratio": 1.5, "wake_word": "hey mycroft", "phonemes": "HH EY . M AY K R AO F T", "threshold": 1e-90, "stand_up_word": "wake up" }, "hotwords": { "hey mycroft": { "module": "pocketsphinx", "phonemes": "HH EY . M AY K R AO F T", "threshold": 1e-90 }, "wake up": { "module": "pocketsphinx", "phonemes": "W EY K . AH P", "threshold": 1e-20 } } } mock_config_get.return_value = test_config rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_wake_word_recognizer(rl)
def testHotwordConfig(self, mock_config_get): """Ensure that the fallback method collecting phonemes etc. from the listener config works. """ test_config = base_config() mock_config_get.return_value = test_config # Set fallback values test_config['listener']['phonemes'] = 'HH EY . V IH K T AO R IY AH' test_config['listener']['threshold'] = 1e-90 steve_conf = { 'model': 'pocketsphinx', 'phonemes': 'S T IY V .', 'threshold': 1e-42 } test_config['hotwords']['steve'] = steve_conf test_config['listener']['wake_word'] = 'steve' rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, 'steve') # Ensure phonemes and threshold are poulated from listener config # if they're missing # Set fallback values test_config['listener']['phonemes'] = 'S T IY V .' test_config['listener']['threshold'] = 1e-90 steve_conf = { 'model': 'pocketsphinx' } test_config['hotwords']['steve'] = steve_conf test_config['listener']['wake_word'] = 'steve' rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, 'steve') self.assertEqual(rl.wakeword_recognizer.phonemes, 'S T IY V .')
def testListenerConfig(self, mock_config_get): """Ensure that the fallback method collecting phonemes etc. from the listener config works. """ test_config = base_config() mock_config_get.return_value = test_config # Test "Hey Mycroft" rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, "hey mycroft") # Test "Hey Victoria" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'HH EY . V IH K T AO R IY AH' test_config['listener']['threshold'] = 1e-90 rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, "hey victoria") # Test Invalid" test_config['listener']['wake_word'] = 'hey victoria' test_config['listener']['phonemes'] = 'ZZZZZZZZZZZZ' rl = RecognizerLoop() self.assertEqual(rl.wakeword_recognizer.key_phrase, "hey mycroft")
def main(ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping, watchdog=lambda: None): global bus global loop global config try: reset_sigint_handler() PIDLock("voice") bus = MessageBusClient() # Mycroft messagebus, see mycroft.messagebus Configuration.set_config_update_handlers(bus) config = Configuration.get() # Register handlers on internal RecognizerLoop bus loop = RecognizerLoop(watchdog) connect_loop_events(loop) connect_bus_events(bus) create_daemon(bus.run_forever) create_daemon(loop.run) except Exception as e: error_hook(e) else: ready_hook() wait_for_exit_signal() stopping_hook()
def setUp(self): self.recognizer = RecognizerLoop.create_mycroft_recognizer(16000, "en-us")
class AudioConsumerTest(unittest.TestCase): """ AudioConsumerTest """ def setUp(self): self.loop = RecognizerLoop() self.queue = Queue() self.recognizer = MockRecognizer() self.consumer = AudioConsumer(self.loop.state, self.queue, self.loop, MycroftSTT(), self.loop.wakeup_recognizer, self.loop.wakeword_recognizer) def __create_sample_from_test_file(self, sample_name): root_dir = dirname(dirname(dirname(__file__))) filename = join(root_dir, 'unittests', 'client', 'data', sample_name + '.wav') wavfile = WavFile(filename) with wavfile as source: return AudioData(source.stream.read(), wavfile.SAMPLE_RATE, wavfile.SAMPLE_WIDTH) def test_word_extraction(self): """ This is intended to test the extraction of the word: ``mycroft``. The values for ``ideal_begin`` and ``ideal_end`` were found using an audio tool like Audacity and they represent a sample value position of the audio. ``tolerance`` is an acceptable margin error for the distance between the ideal and actual values found by the ``WordExtractor`` """ # TODO: implement WordExtractor test without relying on the listener return audio = self.__create_sample_from_test_file('weather_mycroft') self.queue.put(audio) tolerance = 4000 ideal_begin = 70000 ideal_end = 92000 monitor = {} self.recognizer.set_transcriptions(["what's the weather next week"]) def wakeword_callback(message): monitor['pos_begin'] = message.get('pos_begin') monitor['pos_end'] = message.get('pos_end') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.read() actual_begin = monitor.get('pos_begin') self.assertIsNotNone(actual_begin) diff = abs(actual_begin - ideal_begin) self.assertTrue(diff <= tolerance, str(diff) + " is not less than " + str(tolerance)) actual_end = monitor.get('pos_end') self.assertIsNotNone(actual_end) diff = abs(actual_end - ideal_end) self.assertTrue(diff <= tolerance, str(diff) + " is not less than " + str(tolerance)) @unittest.skip('Disabled while unittests are brought upto date') def test_wakeword_in_beginning(self): self.queue.put(self.__create_sample_from_test_file('weather_mycroft')) self.recognizer.set_transcriptions(["what's the weather next week"]) monitor = {} def callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', callback) self.consumer.read() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("what's the weather next week", utterances[0]) @unittest.skip('Disabled while unittests are brought upto date') def test_wakeword(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.recognizer.set_transcriptions(["silence"]) monitor = {} def callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', callback) self.consumer.read() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("silence", utterances[0]) def test_ignore_wakeword_when_sleeping(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.recognizer.set_transcriptions(["not detected"]) self.loop.sleep() monitor = {} def wakeword_callback(message): monitor['wakeword'] = message.get('utterance') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.read() self.assertIsNone(monitor.get('wakeword')) self.assertTrue(self.loop.state.sleeping) def test_wakeup(self): self.queue.put(self.__create_sample_from_test_file('mycroft_wakeup')) self.loop.sleep() self.consumer.read() self.assertFalse(self.loop.state.sleeping) @unittest.skip('Disabled while unittests are brought upto date') def test_stop(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.consumer.read() self.queue.put(self.__create_sample_from_test_file('stop')) self.recognizer.set_transcriptions(["stop"]) monitor = {} def utterance_callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', utterance_callback) self.consumer.read() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("stop", utterances[0]) @unittest.skip('Disabled while unittests are brought upto date') def test_record(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.consumer.read() self.queue.put(self.__create_sample_from_test_file('record')) self.recognizer.set_transcriptions(["record"]) monitor = {} def utterance_callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', utterance_callback) self.consumer.read() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("record", utterances[0])
def setUp(self): rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_mycroft_recognizer(rl, 16000, "en-us")
def main(): global bus global loop global config reset_sigint_handler() PIDLock("voice") bus = WebsocketClient() # Mycroft messagebus, see mycroft.messagebus Configuration.init(bus) config = Configuration.get() # Register handlers on internal RecognizerLoop bus loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:speech.recognition.unknown', handle_unknown) loop.on('speak', handle_speak) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:awoken', handle_awoken) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('recognizer_loop:no_internet', handle_no_internet) # Register handlers for events on main Mycroft messagebus bus.on('open', handle_open) bus.on('complete_intent_failure', handle_complete_intent_failure) bus.on('recognizer_loop:sleep', handle_sleep) bus.on('recognizer_loop:wake_up', handle_wake_up) bus.on('mycroft.mic.mute', handle_mic_mute) bus.on('mycroft.mic.unmute', handle_mic_unmute) bus.on('mycroft.mic.get_status', handle_mic_get_status) bus.on("mycroft.paired", handle_paired) bus.on('recognizer_loop:audio_output_start', handle_audio_start) bus.on('recognizer_loop:audio_output_end', handle_audio_end) bus.on('mycroft.stop', handle_stop) create_daemon(bus.run_forever) create_daemon(loop.run) wait_for_exit_signal()
def main(): global ws global loop global config global tts global tts_hash lock = PIDLock("voice") ws = WebsocketClient() config = ConfigurationManager.get() tts = TTSFactory.create() tts.init(ws) tts_hash = config.get('tts') ConfigurationManager.init(ws) loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('speak', handle_speak) loop.on('recognizer_loop:no_internet', handle_no_internet) ws.on('open', handle_open) ws.on('speak', handle_speak) ws.on( 'multi_utterance_intent_failure', handle_multi_utterance_intent_failure) ws.on('recognizer_loop:sleep', handle_sleep) ws.on('recognizer_loop:wake_up', handle_wake_up) ws.on('mycroft.mic.mute', handle_mic_mute) ws.on('mycroft.mic.unmute', handle_mic_unmute) ws.on('mycroft.stop', handle_stop) ws.on("mycroft.paired", handle_paired) ws.on('recognizer_loop:audio_output_start', handle_audio_start) ws.on('recognizer_loop:audio_output_end', handle_audio_end) event_thread = Thread(target=connect) event_thread.setDaemon(True) event_thread.start() try: loop.run() except KeyboardInterrupt, e: tts.playback.stop() tts.playback.join() logger.exception(e) sys.exit()
def __init__(self, samp_rate): print() # Pad debug messages self.ww_recognizer = RecognizerLoop().create_mycroft_recognizer( samp_rate, 'en-us') self.listener = ResponsiveRecognizer(self.ww_recognizer) print()
def main(): global ws global loop global config lock = PIDLock("voice") ws = WebsocketClient() config = Configuration.get() Configuration.init(ws) loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('speak', handle_speak) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('recognizer_loop:no_internet', handle_no_internet) ws.on('open', handle_open) ws.on('complete_intent_failure', handle_complete_intent_failure) ws.on('recognizer_loop:sleep', handle_sleep) ws.on('recognizer_loop:wake_up', handle_wake_up) ws.on('mycroft.mic.mute', handle_mic_mute) ws.on('mycroft.mic.unmute', handle_mic_unmute) ws.on("mycroft.paired", handle_paired) ws.on('recognizer_loop:audio_output_start', handle_audio_start) ws.on('recognizer_loop:audio_output_end', handle_audio_end) ws.on('mycroft.stop', handle_stop) event_thread = Thread(target=connect) event_thread.setDaemon(True) event_thread.start() try: loop.run() except KeyboardInterrupt, e: LOG.exception(e) sys.exit()
def main(): global ws global loop ws = WebsocketClient() tts.init(ws) ConfigurationManager.init(ws) loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:waiting_for_wakeword', handle_waiting_for_wakeword) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('recognizer_loop:tooshort', handle_tooshort) loop.on('speak', handle_speak) ws.on('open', handle_open) ws.on('speak', handle_speak) ws.on('multi_utterance_intent_failure', handle_multi_utterance_intent_failure) ws.on('recognizer_loop:sleep', handle_sleep) ws.on('recognizer_loop:mute', handle_mute) ws.on('recognizer_loop:wake_up', handle_wake_up) ws.on('mycroft.stop', handle_stop) ws.on("mycroft.paired", handle_paired) event_thread = Thread(target=connect) event_thread.setDaemon(True) event_thread.start() #tts.execute("Hello! I am Teddy, your TV watching companion.") tts.execute("To get my attention, say Hey Teddy!") try: loop.run() except KeyboardInterrupt, e: logger.exception(e) event_thread.exit() sys.exit()
class AudioConsumerTest(unittest.TestCase): """ AudioConsumerTest """ def setUp(self): self.loop = RecognizerLoop() self.queue = Queue() self.recognizer = MockRecognizer() self.consumer = AudioConsumer( self.loop.state, self.queue, self.loop, self.loop.wakeup_recognizer, self.loop.mycroft_recognizer, RemoteRecognizerWrapperFactory.wrap_recognizer( self.recognizer, 'google')) def __create_sample_from_test_file(self, sample_name): root_dir = dirname(dirname(dirname(__file__))) filename = join( root_dir, 'test', 'client', 'data', sample_name + '.wav') wavfile = WavFile(filename) with wavfile as source: return AudioData( source.stream.read(), wavfile.SAMPLE_RATE, wavfile.SAMPLE_WIDTH) def test_word_extraction(self): """ This is intended to test the extraction of the word: ``mycroft``. The values for ``ideal_begin`` and ``ideal_end`` were found using an audio tool like Audacity and they represent a sample value position of the audio. ``tolerance`` is an acceptable margin error for the distance between the ideal and actual values found by the ``WordExtractor`` """ # TODO: implement WordExtractor test without relying on the listener return audio = self.__create_sample_from_test_file('weather_mycroft') self.queue.put(audio) tolerance = 4000 ideal_begin = 70000 ideal_end = 92000 monitor = {} self.recognizer.set_transcriptions(["what's the weather next week"]) def wakeword_callback(message): monitor['pos_begin'] = message.get('pos_begin') monitor['pos_end'] = message.get('pos_end') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.read_audio() actual_begin = monitor.get('pos_begin') self.assertIsNotNone(actual_begin) diff = abs(actual_begin - ideal_begin) self.assertTrue( diff <= tolerance, str(diff) + " is not less than " + str(tolerance)) actual_end = monitor.get('pos_end') self.assertIsNotNone(actual_end) diff = abs(actual_end - ideal_end) self.assertTrue( diff <= tolerance, str(diff) + " is not less than " + str(tolerance)) def test_wakeword_in_beginning(self): self.queue.put(self.__create_sample_from_test_file('weather_mycroft')) self.recognizer.set_transcriptions(["what's the weather next week"]) monitor = {} def callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', callback) self.consumer.read_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("what's the weather next week", utterances[0]) def test_wakeword(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.recognizer.set_transcriptions(["silence"]) monitor = {} def callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', callback) self.consumer.read_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("silence", utterances[0]) def test_ignore_wakeword_when_sleeping(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.recognizer.set_transcriptions(["not detected"]) self.loop.sleep() monitor = {} def wakeword_callback(message): monitor['wakeword'] = message.get('utterance') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.read_audio() self.assertIsNone(monitor.get('wakeword')) self.assertTrue(self.loop.state.sleeping) def test_wakeup(self): self.queue.put(self.__create_sample_from_test_file('mycroft_wakeup')) self.loop.sleep() self.consumer.read_audio() self.assertFalse(self.loop.state.sleeping) def test_stop(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.consumer.read_audio() self.queue.put(self.__create_sample_from_test_file('stop')) self.recognizer.set_transcriptions(["stop"]) monitor = {} def utterance_callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', utterance_callback) self.consumer.read_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("stop", utterances[0]) def test_record(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.consumer.read_audio() self.queue.put(self.__create_sample_from_test_file('record')) self.recognizer.set_transcriptions(["record"]) monitor = {} def utterance_callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', utterance_callback) self.consumer.read_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("record", utterances[0])
class AudioConsumerTest(unittest.TestCase): """ AudioConsumerTest """ def setUp(self): self.loop = RecognizerLoop() self.queue = Queue() self.recognizer = MockRecognizer() self.consumer = AudioConsumer( self.loop.state, self.queue, self.loop, self.loop.wakeup_recognizer, self.loop.ww_recognizer, RemoteRecognizerWrapperFactory.wrap_recognizer(self.recognizer, 'google'), self.loop.wakeup_prefixes, self.loop.wakeup_words) def __create_sample_from_test_file(self, sample_name): root_dir = dirname(dirname(dirname(__file__))) filename = join(root_dir, 'test', 'client', 'data', sample_name + '.wav') wavfile = WavFile(filename) with wavfile as source: return AudioData(source.stream.read(), wavfile.SAMPLE_RATE, wavfile.SAMPLE_WIDTH) def test_audio_pos_front_back(self): audio = self.__create_sample_from_test_file('mycroft_in_utterance') self.queue.put(audio) TRUE_POS_BEGIN = 69857 + int(WakewordExtractor.TRIM_SECONDS * audio.sample_rate * audio.sample_width) TRUE_POS_END = 89138 - int(WakewordExtractor.TRIM_SECONDS * audio.sample_rate * audio.sample_width) TOLERANCE_RANGE_FRAMES = WakewordExtractor.MAX_ERROR_SECONDS * audio.sample_rate * audio.sample_width monitor = {} self.recognizer.set_transcriptions(["what's the weather next week", ""]) def wakeword_callback(message): monitor['pos_begin'] = message.get('pos_begin') monitor['pos_end'] = message.get('pos_end') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.try_consume_audio() pos_begin = monitor.get('pos_begin') self.assertIsNotNone(pos_begin) diff = abs(pos_begin - TRUE_POS_BEGIN) self.assertTrue(diff <= TOLERANCE_RANGE_FRAMES, str(diff) + " is not less than " + str(TOLERANCE_RANGE_FRAMES)) pos_end = monitor.get('pos_end') self.assertIsNotNone(pos_end) diff = abs(pos_end - TRUE_POS_END) self.assertTrue(diff <= TOLERANCE_RANGE_FRAMES, str(diff) + " is not less than " + str(TOLERANCE_RANGE_FRAMES)) def test_wakeword_in_beginning(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) monitor = {} self.recognizer.set_transcriptions(["what's the weather next week", ""]) def callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', callback) self.consumer.try_consume_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("what's the weather next week", utterances[0]) def test_wakeword_in_phrase(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) monitor = {} self.recognizer.set_transcriptions(["he can do other stuff too", "what's the weather in cincinnati"]) def callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', callback) self.consumer.try_consume_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 2) self.assertEquals("he can do other stuff too", utterances[0]) self.assertEquals("what's the weather in cincinnati", utterances[1]) def test_call_and_response(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) monitor = {} self.recognizer.set_transcriptions(["mycroft",""]) def wakeword_callback(message): monitor['wakeword'] = message.get('utterance') def utterance_callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.try_consume_audio() self.assertIsNotNone(monitor.get('wakeword')) self.queue.put(self.__create_sample_from_test_file('mycroft')) self.recognizer.set_transcriptions(["what's the weather next week", ""]) self.loop.once('recognizer_loop:utterance', utterance_callback) self.consumer.try_consume_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("what's the weather next week", utterances[0]) def test_ignore_wakeword_when_sleeping(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.loop.sleep() monitor = {} self.recognizer.set_transcriptions(["", ""]) def wakeword_callback(message): monitor['wakeword'] = message.get('utterance') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.try_consume_audio() self.assertIsNone(monitor.get('wakeword')) self.assertTrue(self.loop.state.sleeping)
def main(): global client global loop client = WebsocketClient() device_index = config.get('speech_client').get('device_index') if device_index: device_index = int(device_index) loop = RecognizerLoop(device_index=device_index) loop.on('recognizer_loop:listening', handle_listening) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:utterance', handle_utterance) loop.on('speak', handle_speak) client.on('speak', handle_speak) client.on('multi_utterance_intent_failure', handle_multi_utterance_intent_failure) client.on('recognizer_loop:sleep', handle_sleep) client.on('recognizer_loop:wake_up', handle_wake_up) event_thread = Thread(target=connect) event_thread.setDaemon(True) event_thread.start() try: loop.run() except KeyboardInterrupt, e: event_thread.exit() sys.exit()
def main(): global client global loop client = WebsocketClient() device_index = config.get('speech_client').get('device_index') if device_index: device_index = int(device_index) loop = RecognizerLoop(device_index=device_index) loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('speak', handle_speak) client.on('speak', handle_speak) client.on( 'multi_utterance_intent_failure', handle_multi_utterance_intent_failure) client.on('recognizer_loop:sleep', handle_sleep) client.on('recognizer_loop:wake_up', handle_wake_up) client.on('mycroft.stop', handle_stop) event_thread = Thread(target=connect) event_thread.setDaemon(True) event_thread.start() try: subprocess.call('echo "eyes.reset" >/dev/ttyAMA0', shell=True) except: pass try: loop.run() except KeyboardInterrupt, e: logger.exception(e) event_thread.exit() sys.exit()
def setUp(self): rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_wake_word_recognizer(rl)
class AudioConsumerTest(unittest.TestCase): """ AudioConsumerTest """ def setUp(self): self.loop = RecognizerLoop() self.queue = Queue() self.recognizer = MockRecognizer() self.consumer = AudioConsumer( self.loop.state, self.queue, self.loop, self.loop.wakeup_recognizer, self.loop.ww_recognizer, RemoteRecognizerWrapperFactory.wrap_recognizer( self.recognizer, 'google'), self.loop.wakeup_prefixes, self.loop.wakeup_words) def __create_sample_from_test_file(self, sample_name): root_dir = dirname(dirname(dirname(__file__))) filename = join(root_dir, 'test', 'client', 'data', sample_name + '.wav') wavfile = WavFile(filename) with wavfile as source: return AudioData(source.stream.read(), wavfile.SAMPLE_RATE, wavfile.SAMPLE_WIDTH) def test_audio_pos_front_back(self): audio = self.__create_sample_from_test_file('mycroft_in_utterance') self.queue.put(audio) TRUE_POS_BEGIN = 69857 + int(WakewordExtractor.TRIM_SECONDS * audio.sample_rate * audio.sample_width) TRUE_POS_END = 89138 - int(WakewordExtractor.TRIM_SECONDS * audio.sample_rate * audio.sample_width) TOLERANCE_RANGE_FRAMES = (WakewordExtractor.MAX_ERROR_SECONDS * audio.sample_rate * audio.sample_width) monitor = {} self.recognizer.set_transcriptions( ["what's the weather next week", ""]) def wakeword_callback(message): monitor['pos_begin'] = message.get('pos_begin') monitor['pos_end'] = message.get('pos_end') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.try_consume_audio() pos_begin = monitor.get('pos_begin') self.assertIsNotNone(pos_begin) diff = abs(pos_begin - TRUE_POS_BEGIN) self.assertTrue( diff <= TOLERANCE_RANGE_FRAMES, str(diff) + " is not less than " + str(TOLERANCE_RANGE_FRAMES)) pos_end = monitor.get('pos_end') self.assertIsNotNone(pos_end) diff = abs(pos_end - TRUE_POS_END) self.assertTrue( diff <= TOLERANCE_RANGE_FRAMES, str(diff) + " is not less than " + str(TOLERANCE_RANGE_FRAMES)) def test_wakeword_in_beginning(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) monitor = {} self.recognizer.set_transcriptions( ["what's the weather next week", ""]) def callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', callback) self.consumer.try_consume_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("what's the weather next week", utterances[0]) def test_wakeword_in_phrase(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) monitor = {} self.recognizer.set_transcriptions( ["he can do other stuff too", "what's the weather in cincinnati"]) def callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:utterance', callback) self.consumer.try_consume_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 2) self.assertEquals("he can do other stuff too", utterances[0]) self.assertEquals("what's the weather in cincinnati", utterances[1]) def test_call_and_response(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) monitor = {} self.recognizer.set_transcriptions(["mycroft", ""]) def wakeword_callback(message): monitor['wakeword'] = message.get('utterance') def utterance_callback(message): monitor['utterances'] = message.get('utterances') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.try_consume_audio() self.assertIsNotNone(monitor.get('wakeword')) self.queue.put(self.__create_sample_from_test_file('mycroft')) self.recognizer.set_transcriptions( ["what's the weather next week", ""]) self.loop.once('recognizer_loop:utterance', utterance_callback) self.consumer.try_consume_audio() utterances = monitor.get('utterances') self.assertIsNotNone(utterances) self.assertTrue(len(utterances) == 1) self.assertEquals("what's the weather next week", utterances[0]) def test_ignore_wakeword_when_sleeping(self): self.queue.put(self.__create_sample_from_test_file('mycroft')) self.loop.sleep() monitor = {} self.recognizer.set_transcriptions(["", ""]) def wakeword_callback(message): monitor['wakeword'] = message.get('utterance') self.loop.once('recognizer_loop:wakeword', wakeword_callback) self.consumer.try_consume_audio() self.assertIsNone(monitor.get('wakeword')) self.assertTrue(self.loop.state.sleeping)
def main(): global ws global loop ws = WebsocketClient() tts.init(ws) ConfigurationManager.init(ws) loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('speak', handle_speak) ws.on('open', handle_open) ws.on('speak', handle_speak) ws.on( 'multi_utterance_intent_failure', handle_multi_utterance_intent_failure) ws.on('recognizer_loop:sleep', handle_sleep) ws.on('recognizer_loop:wake_up', handle_wake_up) ws.on('mycroft.stop', handle_stop) ws.on("mycroft.paired", handle_paired) event_thread = Thread(target=connect) event_thread.setDaemon(True) event_thread.start() try: loop.run() except KeyboardInterrupt, e: logger.exception(e) event_thread.exit() sys.exit()
def main(): global client global loop client = WebsocketClient() device_index = config.get('speech_client').get('device_index') if device_index: device_index = int(device_index) loop = RecognizerLoop(device_index=device_index) loop.on('recognizer_loop:listening', handle_listening) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:utterance', handle_utterance) loop.on('speak', handle_speak) client.on('speak', handle_speak) client.on( 'multi_utterance_intent_failure', handle_multi_utterance_intent_failure) client.on('recognizer_loop:sleep', handle_sleep) client.on('recognizer_loop:wake_up', handle_wake_up) event_thread = Thread(target=connect) event_thread.setDaemon(True) event_thread.start() try: loop.run() except KeyboardInterrupt, e: event_thread.exit() sys.exit()
def main(): global client global loop client = WebsocketClient() device_index = config.get('speech_client').get('device_index') if device_index: device_index = int(device_index) loop = RecognizerLoop(device_index=device_index) loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('speak', handle_speak) client.on('speak', handle_speak) client.on('multi_utterance_intent_failure', handle_multi_utterance_intent_failure) client.on('recognizer_loop:sleep', handle_sleep) client.on('recognizer_loop:wake_up', handle_wake_up) client.on('mycroft.stop', handle_stop) event_thread = Thread(target=connect) event_thread.setDaemon(True) event_thread.start() try: subprocess.call('echo "eyes.reset" >/dev/ttyAMA0', shell=True) except: pass try: loop.run() except KeyboardInterrupt, e: logger.exception(e) event_thread.exit() sys.exit()
def setUp(self): with mock.patch('mycroft.configuration.Configuration.get') as \ mock_config_get: mock_config_get.return_value = base_config() rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_wake_word_recognizer(rl)
def main(): global ws global loop ws = WebsocketClient() tts.init(ws) ConfigurationManager.init(ws) loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('speak', handle_speak) ws.on('open', handle_open) ws.on('speak', handle_speak) ws.on('multi_utterance_intent_failure', handle_multi_utterance_intent_failure) ws.on('recognizer_loop:sleep', handle_sleep) ws.on('recognizer_loop:wake_up', handle_wake_up) ws.on('mycroft.stop', handle_stop) ws.on("mycroft.paired", handle_paired) event_thread = Thread(target=connect) event_thread.setDaemon(True) event_thread.start() try: loop.run() except KeyboardInterrupt, e: logger.exception(e) event_thread.exit() sys.exit()
def main(): global ws global loop reset_sigint_handler() PIDLock("voice") ws = WebsocketClient() Configuration.init(ws) loop = RecognizerLoop() loop.on('recognizer_loop:utterance', handle_utterance) loop.on('recognizer_loop:speech.recognition.unknown', handle_unknown) loop.on('speak', handle_speak) loop.on('recognizer_loop:record_begin', handle_record_begin) loop.on('recognizer_loop:awoken', handle_awoken) loop.on('recognizer_loop:wakeword', handle_wakeword) loop.on('recognizer_loop:record_end', handle_record_end) loop.on('recognizer_loop:no_internet', handle_no_internet) ws.on('open', handle_open) ws.on('complete_intent_failure', handle_complete_intent_failure) ws.on('recognizer_loop:sleep', handle_sleep) ws.on('recognizer_loop:wake_up', handle_wake_up) ws.on('mycroft.mic.mute', handle_mic_mute) ws.on('mycroft.mic.unmute', handle_mic_unmute) ws.on('mycroft.mic.get_status', handle_mic_get_status) ws.on("mycroft.paired", handle_paired) ws.on('recognizer_loop:audio_output_start', handle_audio_start) ws.on('recognizer_loop:audio_output_end', handle_audio_end) ws.on('mycroft.stop', handle_stop) create_daemon(ws.run_forever) create_daemon(loop.run) wait_for_exit_signal()
def __init__(self, samp_rate): print() # Pad debug messages self.ww_recognizer = RecognizerLoop().create_wake_word_recognizer() self.listener = ResponsiveRecognizer(self.ww_recognizer) self.listener.config['confirm_listening'] = False print()
def setUp(self): rl = RecognizerLoop() self.recognizer = RecognizerLoop.create_mycroft_recognizer( rl, 16000, "en-us")