Issues 14 - Listener Improvements
- Renaming methods name to convey more meaning - Renaming variable names to disambiguate - Adding description for word extractor testpull/45/head
parent
a8df44199a
commit
08d07360da
|
|
@ -113,15 +113,15 @@ class AudioConsumer(threading.Thread):
|
|||
timer.start()
|
||||
|
||||
if self.state.sleeping:
|
||||
self.wake_up(audio)
|
||||
self.process_wake_up(audio)
|
||||
elif self.state.skip_wakeword:
|
||||
self.skip_wake_word(audio)
|
||||
self.process_skip_wake_word(audio)
|
||||
else:
|
||||
self.wake_word(audio, timer)
|
||||
self.process_wake_word(audio, timer)
|
||||
|
||||
self.metrics.flush()
|
||||
|
||||
def wake_up(self, audio):
|
||||
def process_wake_up(self, audio):
|
||||
if self.wakeup_recognizer.is_recognized(audio.frame_data,
|
||||
self.metrics):
|
||||
SessionManager.touch()
|
||||
|
|
@ -129,7 +129,7 @@ class AudioConsumer(threading.Thread):
|
|||
self.__speak("I'm awake.") # TODO: Localization
|
||||
self.metrics.increment("mycroft.wakeup")
|
||||
|
||||
def wake_word(self, audio, timer):
|
||||
def process_wake_word(self, audio, timer):
|
||||
hyp = self.mycroft_recognizer.transcribe(audio.frame_data,
|
||||
self.metrics)
|
||||
|
||||
|
|
@ -163,7 +163,7 @@ class AudioConsumer(threading.Thread):
|
|||
self.state.skip_wakeword = True
|
||||
self.metrics.increment("mycroft.wakeword")
|
||||
|
||||
def skip_wake_word(self, audio):
|
||||
def process_skip_wake_word(self, audio):
|
||||
SessionManager.touch()
|
||||
try:
|
||||
self.transcribe([audio])
|
||||
|
|
|
|||
|
|
@ -52,12 +52,20 @@ class AudioConsumerTest(unittest.TestCase):
|
|||
source.stream.read(), wavfile.SAMPLE_RATE,
|
||||
wavfile.SAMPLE_WIDTH)
|
||||
|
||||
def test_audio_pos_front_back(self):
|
||||
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``
|
||||
"""
|
||||
|
||||
audio = self.__create_sample_from_test_file('weather_mycroft')
|
||||
self.queue.put(audio)
|
||||
tolerance = 4000
|
||||
begin = 70000
|
||||
end = 92000
|
||||
ideal_begin = 70000
|
||||
ideal_end = 92000
|
||||
|
||||
monitor = {}
|
||||
self.recognizer.set_transcriptions(["what's the weather next week"])
|
||||
|
|
@ -69,16 +77,16 @@ class AudioConsumerTest(unittest.TestCase):
|
|||
self.loop.once('recognizer_loop:wakeword', wakeword_callback)
|
||||
self.consumer.read_audio()
|
||||
|
||||
pos_begin = monitor.get('pos_begin')
|
||||
self.assertIsNotNone(pos_begin)
|
||||
diff = abs(pos_begin - begin)
|
||||
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))
|
||||
|
||||
pos_end = monitor.get('pos_end')
|
||||
self.assertIsNotNone(pos_end)
|
||||
diff = abs(pos_end - end)
|
||||
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))
|
||||
|
|
|
|||
Loading…
Reference in New Issue