Эх сурвалжийг харах

update neuron module to use the new TTS module implementation

nico 8 жил өмнө
parent
commit
cf9b45af16
2 өөрчлөгдсөн 45 нэмэгдсэн , 24 устгасан
  1. 13 11
      core/NeuronModule.py
  2. 32 13
      test.py

+ 13 - 11
core/NeuronModule.py

@@ -100,21 +100,23 @@ class NeuronModule(object):
             tts_message = self._get_message_from_dict(message)
 
         if tts_message is not None:
-            # get an instance of the target TTS
-            tts_instance = Utils.get_dynamic_class_instantiation("tts", self.tts.capitalize())
-            tts_args = None
-            for tts_object in self.settings.ttss:
-                if tts_object.name == self.tts:
-                    tts_args = tts_object.parameters
-                    logger.debug("NeuronModule: tts_args: %s" % tts_args)
-
             logger.debug("tts_message to say: %s" % tts_message)
+
+            # create a tts object from the tts the user want to user
+            tts_object = next((x for x in self.settings.ttss if x.name == self.tts), None)
+            if tts_object is None:
+                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_args = self._update_cache_var(self.override_cache, tts_args)
-            logger.debug("NeuroneModule: TTS args: %s" % tts_args)
+                tts_object.parameter = self._update_cache_var(self.override_cache, tts_object.parameter)
+
+            logger.debug("NeuroneModule: TTS args: %s" % tts_object)
 
-            tts_instance.say(words=tts_message, **(tts_args if tts_args is not None else {}))
+            # get the instance of the TTS module
+            tts_module_instance = Utils.get_dynamic_class_instantiation("tts", tts_object.name.capitalize(),
+                                                                        tts_object.parameters)
+            # generate the audio file and play it
+            tts_module_instance.say(tts_message)
 
     def _get_message_from_dict(self, message_dict):
         """

+ 32 - 13
test.py

@@ -1,6 +1,10 @@
 # coding: utf8
 import logging
 
+from core import OrderAnalyser
+from core import Utils
+from core.ConfigurationManager import SettingLoader
+from core.ConfigurationManager.BrainLoader import BrainLoader
 from core.Players import Mplayer
 
 logging.basicConfig()
@@ -11,26 +15,41 @@ logger.setLevel(logging.DEBUG)
 # oa = OrderAnalyser(order=order)
 # oa.start()
 
-# SettingLoader.get_settings()
-#
-# brain = BrainLoader.get_brain()
-#
-# order = "bonjour2"
-#
-# oa = OrderAnalyser(order=order, brain=brain)
-#
-# oa.start()
-
 
-file_path = "/tmp/kalliope/tts/Acapela/sonid15/Manon.378f97b9ae266e30898396f4c4f7e159.tts"
 
+brain = BrainLoader.get_brain()
 
-player = Mplayer()
-player.play(file_path)
+order = "bonjour"
 
+oa = OrderAnalyser(order=order, brain=brain)
 
+oa.start()
 
 
+# settings = SettingLoader.get_settings()
+#
+# tts_name_to_use = "pico2wave"
+# sentence_to_say = "bonjour monsieur, je m'appelle Kalliopé"
+#
+#
+# def _get_tts_object_from_name(tts_name_to_use):
+#     """
+#     Return a Tts object from the nae of the Tss. Get parameters in settings
+#     :param tts_name_to_use:
+#     :return:
+#     """
+#     return next((x for x in settings.ttss if x.name == tts_name_to_use), None)
+#
+#
+# # create a tts object from the tts the user want to user
+# tts_object = _get_tts_object_from_name(tts_name_to_use)
+#
+# if tts_object is None:
+#     print "TTS module name %s not found in settings" % tts_name_to_use
+#
+# else:
+#     tts_module_instance = Utils.get_dynamic_class_instantiation("tts", tts_object.name.capitalize(), tts_object.parameters)
+#     tts_module_instance.say(sentence_to_say)