瀏覽代碼

fix thread

nico 8 年之前
父節點
當前提交
ae37c80a3e
共有 2 個文件被更改,包括 11 次插入9 次删除
  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
         # get global configuration
         sl = SettingLoader()
         sl = SettingLoader()
         self.settings = sl.settings
         self.settings = sl.settings
+        # keep in memory the order to process
+        self.order_to_process = None
 
 
         # Starting the rest API
         # Starting the rest API
         self._start_rest_api()
         self._start_rest_api()
@@ -181,17 +183,17 @@ class MainController:
         :type order: str
         :type order: str
         """
         """
         logger.debug("order listener callback called. Order to process: %s" % order)
         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
         Start the order analyser with the caught order to process
         :param order: the text order to analyse
         :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()
             order_analyser.start()
         # return to the state "unpausing_trigger"
         # return to the state "unpausing_trigger"
         self.unpause_trigger()
         self.unpause_trigger()

+ 3 - 3
kalliope/stt/Utils.py

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