Browse Source

add main controller

Nicolas Marcq 8 years ago
parent
commit
8dbd63d5fc
4 changed files with 46 additions and 14 deletions
  1. 8 4
      core/JarvisTrigger.py
  2. 23 0
      core/MainController.py
  3. 12 5
      core/OrderListener.py
  4. 3 5
      jarvis.py

+ 8 - 4
core/JarvisTrigger.py

@@ -6,12 +6,17 @@ class JarvisTrigger:
     """
     Class used to catch the trigger word before listening for an order to process
     """
-    def __init__(self):
+    def __init__(self, main_controller):
+        """
+
+        :param main_controller: Main controller of the app
+        :type main_controller MainController
+        """
+        self.main_controller = main_controller
         # TODO update this to load the file from settings
         self.model = "stt/snowboy/resources/jarviss.pmdl"
         # boolean used to stop the snowbow listening
         self.interrupted = False
-        self.order_listener = OrderListener()
 
     def interrupt_callback(self):
         """
@@ -29,8 +34,7 @@ class JarvisTrigger:
         detector = snowboydecoder.HotwordDetector(self.model, sensitivity=0.4)
 
         # start snowboy loop
-        # TODO change to callback, call a function that wait for an audio order
-        detector.start(detected_callback=self.order_listener.hotword_detected,
+        detector.start(detected_callback=self.main_controller.get_order_listenner().hotword_detected,
                        interrupt_check=self.interrupt_callback,
                        sleep_time=0.03)
 

+ 23 - 0
core/MainController.py

@@ -0,0 +1,23 @@
+from core.JarvisTrigger import JarvisTrigger
+from core.OrderListener import OrderListener
+
+
+class MainController:
+    def __init__(self):
+        # create an order listener object
+        self.order_listener = OrderListener(self)
+        # Wait that the jarvis trigger is pronounced by the user
+        self.jarvis_triger = JarvisTrigger(self)
+
+    def get_order_listenner(self):
+        return self.order_listener
+
+    def start(self):
+        self.jarvis_triger.start()
+
+    def pause_jarvis_trigger(self):
+        """
+        The hotwork to wake up jarvis has been detected, we pause the snowboy process
+        :return:
+        """
+        pass

+ 12 - 5
core/OrderListener.py

@@ -7,10 +7,17 @@ class OrderListener:
     We now wait for an order spoken out loud by the user, translate the order into a text and run the action
      attached to this order from settings
     """
-    def __init__(self):
-        pass
+    def __init__(self, main_controller):
+        """
 
-    def hotword_detected(self):
-        print "Start listening order"
-        say = Say("oui monsieur?")
+        :param main_controller:
+        :type main_controller: MainController
+        """
+        self.main_controller = main_controller
 
+    def hotword_detected(self):
+        # we have detected the hotword, we can now pause the Jarvis Trigger for a while
+        # The user can speak out loud his order during this time.
+        self.main_controller.pause_jarvis_trigger()
+        print "Start listening for order"
+        Say("oui monsieur?")

+ 3 - 5
jarvis.py

@@ -1,14 +1,12 @@
-from core.JarvisTrigger import JarvisTrigger
-from core.OrderListener import OrderListener
+from core.MainController import MainController
 
 
 def main():
     """
     Entry point of jarvis program
     """
-    # Wait that the jarvis trigger is pronounced by the user
-    jarvis_triger = JarvisTrigger()
-    jarvis_triger.start()
+    main_controller = MainController()
+    main_controller.start()
 
 if __name__ == '__main__':
     main()