MainController.py 1.7 KB

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