MainController.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from core.JarvisTrigger import JarvisTrigger
  2. from core.OrderAnalyser import OrderAnalyser
  3. from core.OrderListener import OrderListener
  4. from core.ConfigurationManager.ConfigurationManager import ConfigurationManager
  5. from neurons import Say
  6. class MainController:
  7. def __init__(self, brain_file=None):
  8. self.brain_file = brain_file
  9. # Manage Global Configuration
  10. self.conf = ConfigurationManager().get_settings()
  11. # create an order listener object
  12. self.order_listener = OrderListener(self.get_analyse_order_callback())
  13. # Wait that the jarvis trigger is pronounced by the user
  14. self.jarvis_triger = JarvisTrigger(self)
  15. def start(self):
  16. self.jarvis_triger.start()
  17. def pause_jarvis_trigger(self):
  18. """
  19. The hotwork to wake up jarvis has been detected, we pause the snowboy process
  20. :return:
  21. """
  22. self.jarvis_triger.pause()
  23. def unpause_jarvis_trigger(self):
  24. self.jarvis_triger.unpause()
  25. def hotword_detected(self):
  26. """
  27. # we have detected the hotword, we can now pause the Jarvis Trigger for a while
  28. # The user can speak out loud his order during this time.
  29. :return:
  30. """
  31. # pause the snowboy process
  32. self.pause_jarvis_trigger()
  33. random_answers = self.conf["random_wake_up_answers"]
  34. Say(message=random_answers)
  35. self.order_listener.load_stt_plugin()
  36. def analyse_order(self, order):
  37. """
  38. Receive an order, try to retreive it in the brain.yml to launch to attached plugins
  39. :return:
  40. """
  41. order_analyser = OrderAnalyser(order, main_controller=self, brain_file=self.brain_file)
  42. order_analyser.start()
  43. def get_analyse_order_callback(self):
  44. return self.analyse_order