MainController.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 get_order_listenner(self):
  16. return self.order_listener
  17. def start(self):
  18. self.jarvis_triger.start()
  19. def pause_jarvis_trigger(self):
  20. """
  21. The hotwork to wake up jarvis has been detected, we pause the snowboy process
  22. :return:
  23. """
  24. self.jarvis_triger.pause()
  25. def unpause_jarvis_trigger(self):
  26. self.jarvis_triger.unpause()
  27. def hotword_detected(self):
  28. """
  29. # we have detected the hotword, we can now pause the Jarvis Trigger for a while
  30. # The user can speak out loud his order during this time.
  31. :return:
  32. """
  33. # pause the snowboy process
  34. self.pause_jarvis_trigger()
  35. print "Start listening for order"
  36. random_answers = self.conf["random_wake_up_answers"]
  37. Say(message=random_answers)
  38. self.order_listener.load_stt_plugin()
  39. def analyse_order(self, order):
  40. """
  41. Receive an order, try to retreive it in the brain.yml to launch to attached plugins
  42. :return:
  43. """
  44. order_analyser = OrderAnalyser(order, main_controller=self, brain_file=self.brain_file)
  45. order_analyser.start()
  46. def get_analyse_order_callback(self):
  47. return self.analyse_order