JarvisTrigger.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from stt.snowboy import snowboydecoder
  2. class JarvisTrigger:
  3. """
  4. Class used to catch the trigger word before listening for an order to process
  5. """
  6. def __init__(self):
  7. # TODO update this to load the file from settings
  8. self.model = "stt/snowboy/resources/snowboy.umdl"
  9. # boolean used to stop the snowbow listening
  10. self.interrupted = False
  11. def interrupt_callback(self):
  12. """
  13. This function will be passed to snowboy to stop the main thread
  14. :return:
  15. """
  16. return self.interrupted
  17. def start(self):
  18. """
  19. Start the snowboy thread and wait for a Jarvis trigger word
  20. :return:
  21. """
  22. detector = snowboydecoder.HotwordDetector(self.model, sensitivity=0.5)
  23. # start snowboy loop
  24. # TODO change to callback, call a function that wait for an audio order
  25. detector.start(detected_callback=snowboydecoder.play_audio_file,
  26. interrupt_check=self.interrupt_callback,
  27. sleep_time=0.03)
  28. # we wait that a callback
  29. detector.terminate()
  30. def stop(self):
  31. """
  32. Stop the Snowboy main thread
  33. :return:
  34. """
  35. self.interrupted = True