MainController.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from core.ConfigurationManager import SettingLoader
  2. from core.JarvisTrigger import JarvisTrigger
  3. from core.OrderAnalyser import OrderAnalyser
  4. from core.OrderListener import OrderListener
  5. from neurons import Say
  6. class MainController:
  7. def __init__(self, brain_file=None):
  8. self.brain_file = brain_file
  9. # get global configuration
  10. self.settings = SettingLoader.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. Say(message=self.settings.random_wake_up_answers)
  34. self.order_listener.load_stt_plugin()
  35. def analyse_order(self, order):
  36. """
  37. Receive an order, try to retreive it in the brain.yml to launch to attached plugins
  38. :return:
  39. """
  40. order_analyser = OrderAnalyser(order, main_controller=self, brain_file=self.brain_file)
  41. order_analyser.start()
  42. def get_analyse_order_callback(self):
  43. return self.analyse_order