JarvisTrigger.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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, main_controller):
  7. """
  8. :param main_controller: Main controller of the app
  9. :type main_controller MainController
  10. """
  11. self.main_controller = main_controller
  12. # TODO update this to load the file from settings
  13. self.model = "stt/snowboy/resources/jarviss.pmdl"
  14. # boolean used to stop the snowbow listening
  15. self.interrupted = False
  16. def interrupt_callback(self):
  17. """
  18. This function will be passed to snowboy to stop the main thread
  19. :return:
  20. """
  21. return self.interrupted
  22. def start(self):
  23. """
  24. Start the snowboy thread and wait for a Jarvis trigger word
  25. :return:
  26. """
  27. detector = snowboydecoder.HotwordDetector(self.model, sensitivity=0.5)
  28. # start snowboy loop
  29. detector.start(detected_callback=self.main_controller.hotword_detected,
  30. interrupt_check=self.interrupt_callback,
  31. sleep_time=0.03)
  32. # we wait that a callback
  33. detector.terminate()
  34. def pause(self):
  35. """
  36. Stop the Snowboy main thread
  37. :return:
  38. """
  39. self.interrupted = True
  40. def unpause(self):
  41. self.interrupted = False