Forráskód Böngészése

Merge pull request #261 from Ultchad/neuron_tts_params

update function _update_cache_var to _update_params
Nicolas Marcq 8 éve
szülő
commit
be62e58471
3 módosított fájl, 45 hozzáadás és 13 törlés
  1. 15 0
      Docs/neurons.md
  2. 12 3
      Tests/test_neuron_module.py
  3. 18 10
      kalliope/core/NeuronModule.py

+ 15 - 0
Docs/neurons.md

@@ -159,5 +159,20 @@ neurons:
 
 
 Here, the first neuron will use the default tts as set in the settings.yml file. The second neuron will use the tts "acapela".
 Here, the first neuron will use the default tts as set in the settings.yml file. The second neuron will use the tts "acapela".
 
 
+or with new parameters:
+```yml
+neurons:
+  - say:
+      message:
+        - "Me llamo kalliope"
+      tts:
+        pico2wave:
+          language: "es-ES"
+```
+
+Here,  neuron will use the tts "pico2wave" with "es-ES" language.
+
+
+
 >**Note:** The TTS must has been configured with its required parameters in the settings.yml file. See [TTS documentation](tts.md).
 >**Note:** The TTS must has been configured with its required parameters in the settings.yml file. See [TTS documentation](tts.md).
 
 

+ 12 - 3
Tests/test_neuron_module.py

@@ -37,7 +37,7 @@ class TestNeuronModule(unittest.TestCase):
                 mock_orderListener_start.assert_called_once_with()
                 mock_orderListener_start.assert_called_once_with()
                 mock_orderListener_start.reset_mock()
                 mock_orderListener_start.reset_mock()
 
 
-    def test_update_cache_var(self):
+    def test_update_params(self):
         """
         """
         Test Update the value of the cache in the provided arg list
         Test Update the value of the cache in the provided arg list
         """
         """
@@ -49,7 +49,7 @@ class TestNeuronModule(unittest.TestCase):
         expected_dict = {
         expected_dict = {
             "cache": False
             "cache": False
         }
         }
-        self.assertEquals(NeuronModule._update_cache_var(False, args_dict=args_dict),
+        self.assertEquals(NeuronModule._update_params({'cache': False}, args_dict=args_dict),
                           expected_dict,
                           expected_dict,
                           "Fail to update the cache value from True to False")
                           "Fail to update the cache value from True to False")
         self.assertFalse(args_dict["cache"])
         self.assertFalse(args_dict["cache"])
@@ -61,12 +61,21 @@ class TestNeuronModule(unittest.TestCase):
         expected_dict = {
         expected_dict = {
             "cache": True
             "cache": True
         }
         }
-        self.assertEquals(NeuronModule._update_cache_var(True, args_dict=args_dict),
+        self.assertEquals(NeuronModule._update_params({'cache': True}, args_dict=args_dict),
                           expected_dict,
                           expected_dict,
                           "Fail to update the cache value from False to True")
                           "Fail to update the cache value from False to True")
 
 
         self.assertTrue(args_dict["cache"])
         self.assertTrue(args_dict["cache"])
 
 
+        # {} -> {'language': 'en-US'}
+        args_dict = {}
+        expected_dict = {
+            "language": "en-US"
+        }
+        self.assertEquals(NeuronModule._update_params({'language': 'en-US'}, args_dict=args_dict),
+                          expected_dict,
+                          "Fail to create new parameter: language key and value")
+
     def test_get_message_from_dict(self):
     def test_get_message_from_dict(self):
 
 
         self.neuron_module_test.say_template = self.say_template
         self.neuron_module_test.say_template = self.say_template

+ 18 - 10
kalliope/core/NeuronModule.py

@@ -74,17 +74,24 @@ class NeuronModule(object):
         brain_loader = BrainLoader()
         brain_loader = BrainLoader()
         self.brain = brain_loader.brain
         self.brain = brain_loader.brain
 
 
+        self.override_params = dict()
+        # get if the cache settings is present
+        override_cache = kwargs.get('cache', None)
+        if override_cache is not None:
+            self.override_params['cache'] = override_cache
+
         # check if the user has overrider the TTS
         # check if the user has overrider the TTS
         tts = kwargs.get('tts', None)
         tts = kwargs.get('tts', None)
         if tts is None:
         if tts is None:
             # No tts provided,  we load the default one
             # No tts provided,  we load the default one
             self.tts = self.settings.default_tts_name
             self.tts = self.settings.default_tts_name
+        elif type(tts) is dict:
+            for key, value in tts.iteritems():
+                self.tts = key
+                self.override_params = value
         else:
         else:
             self.tts = tts
             self.tts = tts
 
 
-        # get if the cache settings is present
-        self.override_cache = kwargs.get('cache', None)
-
         # get templates if provided
         # get templates if provided
         # Check if there is a template associate to the output message
         # Check if there is a template associate to the output message
         self.say_template = kwargs.get('say_template', None)
         self.say_template = kwargs.get('say_template', None)
@@ -152,9 +159,9 @@ class NeuronModule(object):
             tts_object = next((x for x in self.settings.ttss if x.name == self.tts), None)
             tts_object = next((x for x in self.settings.ttss if x.name == self.tts), None)
             if tts_object is None:
             if tts_object is None:
                 raise TTSModuleNotFound("The tts module name %s does not exist in settings file" % self.tts)
                 raise TTSModuleNotFound("The tts module name %s does not exist in settings file" % self.tts)
-            # change the cache settings with the one precised for the current neuron
-            if self.override_cache is not None:
-                tts_object.parameters = self._update_cache_var(self.override_cache, tts_object.parameters)
+                   
+            if self.override_params is not None:
+                tts_object.parameters = self._update_params(self.override_params, tts_object.parameters)
 
 
             logger.debug("NeuroneModule: TTS args: %s" % tts_object)
             logger.debug("NeuroneModule: TTS args: %s" % tts_object)
 
 
@@ -243,15 +250,16 @@ class NeuronModule(object):
             return content_file.read()
             return content_file.read()
 
 
     @staticmethod
     @staticmethod
-    def _update_cache_var(new_override_cache, args_dict):
+    def _update_params(new_override_params, args_dict):
         """
         """
-        update the value for the key "cache" in the dict args_list
+        update the value for the keys in the dict args_list
         :param new_override_cache: cache boolean to set in place of the current one in args_list
         :param new_override_cache: cache boolean to set in place of the current one in args_list
         :param args_dict: arg list that contain "cache" to update
         :param args_dict: arg list that contain "cache" to update
-        :return:
+        :return: args_dict updated
         """
         """
         logger.debug("args for TTS plugin before update: %s" % str(args_dict))
         logger.debug("args for TTS plugin before update: %s" % str(args_dict))
-        args_dict["cache"] = new_override_cache
+        for key, value in new_override_params.iteritems():
+            args_dict[key] = value
         logger.debug("args for TTS plugin after update: %s" % str(args_dict))
         logger.debug("args for TTS plugin after update: %s" % str(args_dict))
         return args_dict
         return args_dict