Kaynağa Gözat

STT get a callback function as argument instead of main controler

nico 8 yıl önce
ebeveyn
işleme
7e2b332046
3 değiştirilmiş dosya ile 18 ekleme ve 7 silme
  1. 2 0
      core/MainController.py
  2. 3 3
      core/OrderListener.py
  3. 13 4
      stt/google/Google.py

+ 2 - 0
core/MainController.py

@@ -53,3 +53,5 @@ class MainController:
         order_analyser = OrderAnalyser(order, main_controller=self)
         order_analyser.start()
 
+    def get_analyse_order_callback(self):
+        return self.analyse_order

+ 3 - 3
core/OrderListener.py

@@ -40,10 +40,10 @@ class OrderListener:
         if klass is not None:
             # run the plugin
             if not parameters:
-                klass(self.main_controller)
+                klass(self.main_controller.get_analyse_order_callback())
             elif isinstance(parameters, dict):
-                klass(self.main_controller, **parameters)
+                klass(self.main_controller.get_analyse_order_callback(), **parameters)
             else:
-                klass(self.main_controller, parameters)
+                klass(self.main_controller.get_analyse_order_callback(), parameters)
 
 

+ 13 - 4
stt/google/Google.py

@@ -4,13 +4,20 @@ from core.OrderListener import OrderListener
 
 class Google(OrderListener):
 
-    def __init__(self, main_controller=None, **kwargs):
-        OrderListener.__init__(self, main_controller)
+    def __init__(self, callback=None, **kwargs):
+        """
+        Start recording the microphone and analyse audio with google api
+        :param callback: The callback function to call to send the text
+        :param kwargs:
+        """
+        OrderListener.__init__(self)
 
         """
         Start recording the microphone
         :return:
         """
+        # callback function to call after the translation speech/tex
+        self.callback = callback
         # obtain audio from the microphone
         r = sr.Recognizer()
         with sr.Microphone() as source:
@@ -39,5 +46,7 @@ class Google(OrderListener):
             print("Could not request results from Google Speech Recognition service; {0}".format(e))
 
     def _analyse_audio(self, audio):
-        if self.main_controller is not None:
-            self.main_controller.analyse_order(audio)
+        # if self.main_controller is not None:
+        #     self.main_controller.analyse_order(audio)
+        if self.callback is not None:
+            self.callback(audio)