Browse Source

fix thread

nico 8 years ago
parent
commit
ae37c80a3e
2 changed files with 11 additions and 9 deletions
  1. 8 6
      kalliope/core/MainController.py
  2. 3 3
      kalliope/stt/Utils.py

+ 8 - 6
kalliope/core/MainController.py

@@ -37,6 +37,8 @@ class MainController:
         # get global configuration
         sl = SettingLoader()
         self.settings = sl.settings
+        # keep in memory the order to process
+        self.order_to_process = None
 
         # Starting the rest API
         self._start_rest_api()
@@ -181,17 +183,17 @@ class MainController:
         :type order: str
         """
         logger.debug("order listener callback called. Order to process: %s" % order)
-        self.order_listener_callback_called = False
-        self.next_state(order)
+        self.order_to_process = order
+        self.order_listener_callback_called = True
 
-    def analysing_order_thread(self, order):
+    def analysing_order_thread(self):
         """
         Start the order analyser with the caught order to process
         :param order: the text order to analyse
         """
-        logger.debug("order in analysing_order_thread %s" % order)
-        if order is not None:   # maybe we have received a null audio from STT engine
-            order_analyser = OrderAnalyser(order, brain=self.brain)
+        logger.debug("order in analysing_order_thread %s" % self.order_to_process)
+        if self.order_to_process is not None:   # maybe we have received a null audio from STT engine
+            order_analyser = OrderAnalyser(self.order_to_process, brain=self.brain)
             order_analyser.start()
         # return to the state "unpausing_trigger"
         self.unpause_trigger()

+ 3 - 3
kalliope/stt/Utils.py

@@ -20,7 +20,7 @@ class SpeechRecognition(Thread):
         self.recognizer = sr.Recognizer()
         self.microphone = sr.Microphone()
         self.callback = None
-        self.stop_listening = None
+        self.stop_thread = None
         self.kill_yourself = False
         with self.microphone as source:
             # we only need to calibrate once, before we start listening
@@ -31,11 +31,11 @@ class SpeechRecognition(Thread):
         Start the thread that listen the microphone and then give the audio to the callback method
         """
         Utils.print_info("Say something!")
-        self.stop_listening = self.recognizer.listen_in_background(self.microphone, self.callback)
+        self.stop_thread = self.recognizer.listen_in_background(self.microphone, self.callback)
         while not self.kill_yourself:
             sleep(0.1)
         logger.debug("kill the speech recognition process")
-        self.stop_listening()
+        self.stop_thread()
 
     def start_listening(self):
         """