Browse Source

add STT test to the GUI

nico 8 years ago
parent
commit
faa88bec75
4 changed files with 73 additions and 19 deletions
  1. 10 0
      core/ConfigurationManager/ConfigurationManager.py
  2. 1 1
      core/MainController.py
  3. 13 10
      core/OrderListener.py
  4. 49 8
      core/ShellGui.py

+ 10 - 0
core/ConfigurationManager/ConfigurationManager.py

@@ -143,3 +143,13 @@ class ConfigurationManager:
             raise NoSpeechToTextConfiguration("No text_to_speech in settings")
             raise NoSpeechToTextConfiguration("No text_to_speech in settings")
 
 
         return texts_to_speech
         return texts_to_speech
+
+    @classmethod
+    def get_stt_list(cls):
+        settings = cls.get_settings()
+        try:
+            speech_to_text = settings["speech_to_text"]
+        except KeyError:
+            raise NoSpeechToTextConfiguration("No speech_to_text in settings")
+
+        return speech_to_text

+ 1 - 1
core/MainController.py

@@ -12,7 +12,7 @@ class MainController:
         self.conf = ConfigurationManager().get_settings()
         self.conf = ConfigurationManager().get_settings()
 
 
         # create an order listener object
         # create an order listener object
-        self.order_listener = OrderListener(self)
+        self.order_listener = OrderListener(self.get_analyse_order_callback())
         # Wait that the jarvis trigger is pronounced by the user
         # Wait that the jarvis trigger is pronounced by the user
         self.jarvis_triger = JarvisTrigger(self)
         self.jarvis_triger = JarvisTrigger(self)
 
 

+ 13 - 10
core/OrderListener.py

@@ -4,25 +4,28 @@ from core import ConfigurationManager
 
 
 class OrderListener:
 class OrderListener:
 
 
-    def __init__(self, main_controller=None):
+    def __init__(self, callback=None, stt=None):
         """
         """
         This class is called after we catch the hotword that have woke up JARVIS.
         This class is called after we catch the hotword that have woke up JARVIS.
         We now wait for an order spoken out loud by the user, translate the order into a text and run the action
         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
          attached to this order from settings
-        :param main_controller:
-        :type main_controller: MainController
+        :param callback: callback function to call
+        :param stt: Speech to text plugin name to load. If not provided,
+        we will load the default one set in settings
         """
         """
-        self.main_controller = main_controller
+        self.stt = stt
+        self.callback = callback
         # self.settings = main_controller.conf.settingLoader.get_config()
         # self.settings = main_controller.conf.settingLoader.get_config()
         self.settings = ConfigurationManager().get_settings()
         self.settings = ConfigurationManager().get_settings()
 
 
     def load_stt_plugin(self):
     def load_stt_plugin(self):
-        default_stt_plugin = ConfigurationManager.get_default_speech_to_text()
+        if self.stt is None:
+            self.stt = ConfigurationManager.get_default_speech_to_text()
 
 
-        stt_args = ConfigurationManager.get_stt_args(default_stt_plugin)
+        stt_args = ConfigurationManager.get_stt_args(self.stt)
 
 
         # capitalizes the first letter (because classes have first letter upper case)
         # capitalizes the first letter (because classes have first letter upper case)
-        default_stt_plugin = default_stt_plugin.capitalize()
+        default_stt_plugin = self.stt.capitalize()
         self._run_stt_plugin(default_stt_plugin, stt_args)
         self._run_stt_plugin(default_stt_plugin, stt_args)
 
 
     def _run_stt_plugin(self, stt_plugin, parameters=None):
     def _run_stt_plugin(self, stt_plugin, parameters=None):
@@ -40,10 +43,10 @@ class OrderListener:
         if klass is not None:
         if klass is not None:
             # run the plugin
             # run the plugin
             if not parameters:
             if not parameters:
-                klass(self.main_controller.get_analyse_order_callback())
+                klass(self.callback)
             elif isinstance(parameters, dict):
             elif isinstance(parameters, dict):
-                klass(self.main_controller.get_analyse_order_callback(), **parameters)
+                klass(self.callback, **parameters)
             else:
             else:
-                klass(self.main_controller.get_analyse_order_callback(), parameters)
+                klass(self.callback, parameters)
 
 
 
 

+ 49 - 8
core/ShellGui.py

@@ -2,6 +2,7 @@ from dialog import Dialog
 import locale
 import locale
 
 
 from core import ConfigurationManager
 from core import ConfigurationManager
+from core import OrderListener
 from neurons import Say
 from neurons import Say
 
 
 
 
@@ -35,7 +36,22 @@ class ShellGui:
                 self.show_tts_test_menu()
                 self.show_tts_test_menu()
 
 
     def show_stt_test_menu(self):
     def show_stt_test_menu(self):
-        pass
+        # we get STT from settings
+        stt_list = ConfigurationManager.get_stt_list()
+        print stt_list
+        choices = self._get_choices_tuple_from_list(stt_list)
+
+        code, tag = self.d.menu("Select the STT to test:",
+                                choices=choices)
+
+        if code == self.d.CANCEL:
+            self.show_main_menu()
+
+        if code == self.d.OK:
+            print tag
+            self.d.infobox("Please talk now")
+            order_listener = OrderListener(callback=self.callback_stt, stt=str(tag))
+            order_listener.load_stt_plugin()
 
 
     def show_tts_test_menu(self, sentence_to_test=None):
     def show_tts_test_menu(self, sentence_to_test=None):
         """
         """
@@ -59,13 +75,7 @@ class ShellGui:
             tts_list = ConfigurationManager.get_tts_list()
             tts_list = ConfigurationManager.get_tts_list()
 
 
             # create a list of tuple that can be used by the dialog menu
             # create a list of tuple that can be used by the dialog menu
-            choices = list()
-            for tts in tts_list:
-                for name, settings in tts.iteritems():
-                    print name
-                    print settings
-                    tup = (str(name), str(settings))
-                    choices.append(tup)
+            choices = self._get_choices_tuple_from_list(tts_list)
 
 
             code, tag = self.d.menu("Sentence to test: %s" % sentence_to_test,
             code, tag = self.d.menu("Sentence to test: %s" % sentence_to_test,
                                     choices=choices)
                                     choices=choices)
@@ -86,3 +96,34 @@ class ShellGui:
         """
         """
         Say(message=sentence_to_test, tts=tag)
         Say(message=sentence_to_test, tts=tag)
 
 
+    @staticmethod
+    def _get_choices_tuple_from_list(list_to_convert):
+        """
+        Return a list of tup that can be used in Dialog menu
+        :param stt_list:
+        :return:
+        """
+        # create a list of tuple that can be used by the dialog menu
+        choices = list()
+        for el in list_to_convert:
+            try:
+                for name, settings in el.iteritems():
+                    print name
+                    print settings
+                    tup = (str(name), str(settings))
+                    choices.append(tup)
+            except AttributeError:
+                # sometime there is no settings for the STT key
+                tup = (str(el), str("No settings"))
+                choices.append(tup)
+        return choices
+
+    def callback_stt(self, audio):
+        """
+        Callback function called after the STT has finish his job
+        :param audio: Text from the translated audio
+        """
+        code = self.d.msgbox("The STT engine think you said:\n %s" % audio, width=50)
+
+        if code == self.d.OK:
+            self.show_stt_test_menu()