JarvisTrigger.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from core.OrderListener import OrderListener
  2. from stt.snowboy import snowboydecoder
  3. class JarvisTrigger:
  4. """
  5. Class used to catch the trigger word before listening for an order to process
  6. """
  7. def __init__(self, main_controller):
  8. """
  9. :param main_controller: Main controller of the app
  10. :type main_controller MainController
  11. """
  12. self.main_controller = main_controller
  13. # TODO update this to load the file from settings
  14. self.model = "stt/snowboy/resources/jarviss.pmdl"
  15. # boolean used to stop the snowbow listening
  16. self.interrupted = False
  17. def interrupt_callback(self):
  18. """
  19. This function will be passed to snowboy to stop the main thread
  20. :return:
  21. """
  22. return self.interrupted
  23. def start(self):
  24. """
  25. Start the snowboy thread and wait for a Jarvis trigger word
  26. :return:
  27. """
  28. detector = snowboydecoder.HotwordDetector(self.model, sensitivity=0.4)
  29. # start snowboy loop
  30. detector.start(detected_callback=self.main_controller.get_order_listenner().hotword_detected,
  31. interrupt_check=self.interrupt_callback,
  32. sleep_time=0.03)
  33. # we wait that a callback
  34. detector.terminate()
  35. def stop(self):
  36. """
  37. Stop the Snowboy main thread
  38. :return:
  39. """
  40. self.interrupted = True