浏览代码

neurone get now settings for TTS and load parameters from settings file

nico 8 年之前
父节点
当前提交
dfb1cea7ce
共有 7 个文件被更改,包括 73 次插入15 次删除
  1. 2 1
      brain.yml
  2. 50 0
      core/ConfigurationManager/ConfigurationManager.py
  3. 12 6
      neurons/Neurone.py
  4. 3 1
      neurons/say/say.py
  5. 4 0
      settings.yml
  6. 2 2
      tts/pico2wave/pico2wave.py
  7. 0 5
      tts/voxygen/voxygen.py

+ 2 - 1
brain.yml

@@ -4,9 +4,10 @@
       - say:
           message: "Bonjour monsieur"
       - sleep:
-          seconds: 2
+          seconds: 1
       - say:
           message: "Je suis Jarvice"
+          tts: "voxygen"
     when:
       - order: "dis bonjour"
 

+ 50 - 0
core/ConfigurationManager/ConfigurationManager.py

@@ -45,6 +45,19 @@ class ConfigurationManager:
         except KeyError:
             raise DefaultSpeechToTextNotFound("Attribute default_speech_to_text not found in settings")
 
+    @classmethod
+    def get_default_text_to_speech(cls):
+        settings = cls.get_settings()
+
+        try:
+            default_text_to_speech = settings["default_text_to_speech"]
+            if default_text_to_speech is None:
+                raise DefaultSpeechNull("Attribute default_text_to_speech is null")
+            logging.info("Default TTS: %s" % default_text_to_speech)
+            return default_text_to_speech
+        except KeyError:
+            raise DefaultSpeechToTextNotFound("Attribute default_text_to_speech not found in settings")
+
     @classmethod
     def get_stt_args(cls, default_stt_plugin_name):
         """
@@ -83,3 +96,40 @@ class ConfigurationManager:
         logging.debug("Args for %s STT: %s" % (default_stt_plugin_name, args))
 
         return args
+
+    @classmethod
+    def get_tts_args(cls, tts_name):
+        """
+        Return argument set for the current STT engine
+        :param tts_name: Name of the TTS engine
+        :return:
+        """
+
+        def find(lst, key):
+            """
+            Find a key name in a list
+            :param lst: list()
+            :param key: key name to find i the list
+            :return: Return the dict
+            """
+            for el in lst:
+                try:
+                    if el[key]:
+                        return el[key]
+                except TypeError:
+                    pass
+                except KeyError:
+                    pass
+            return None
+
+        settings = cls.get_settings()
+        try:
+            texts_to_speech = settings["text_to_speech"]
+        except KeyError:
+            raise NoSpeechToTextConfiguration("No text_to_speech in settings")
+
+        logging.debug("Settings file content: %s" % texts_to_speech)
+        # get args
+        args = find(texts_to_speech, tts_name)
+        logging.debug("Args for %s STT: %s" % (tts_name, args))
+        return args

+ 12 - 6
neurons/Neurone.py

@@ -1,16 +1,22 @@
 import importlib
 
+from core import ConfigurationManager
+
 
 class Neurone:
-    def __init__(self, stt=None, tts=None):
-        # TODO load the stt and tts from settings
-        self.stt = "google"
-        self.tts = "pico2wave"
-        #self.tts = "voxygen"
+    def __init__(self, tts=None):
+        # get the name of the plugin
+        # print self.__class__.__name__
+        # load the tts from settings
+        self.tts = tts
+        if tts is None:
+            self.tts = ConfigurationManager.get_default_text_to_speech()
+        # get tts args
+        self.tts_args = ConfigurationManager.get_tts_args(self.tts)
 
     def say(self, message):
         # here we use the tts to make jarvis talk
         # the module is imported on fly, depending on the selected tts from settings
         tts_backend = importlib.import_module("tts." + self.tts)
-        tts_backend.say(message)
+        tts_backend.say(words=message, **self.tts_args)
 

+ 3 - 1
neurons/say/say.py

@@ -8,7 +8,9 @@ class NoMessageException(Exception):
 
 class Say(Neurone):
     def __init__(self, *args , **kwargs):
-        Neurone.__init__(self)
+        # get the tts if is specified
+        tts = kwargs.get('tts', None)
+        Neurone.__init__(self, tts=tts)
 
         # get message to spell out loud
         message = kwargs.get('message', None)

+ 4 - 0
settings.yml

@@ -11,6 +11,7 @@ trigger:
 # This is the STT that will be used by default
 default_speech_to_text: "google"
 # This is the default TTS that will be used by JARVIS to talk.
+#default_text_to_speech: "pico2wave"
 default_text_to_speech: "pico2wave"
 
 # Spreech to Text engines configuration
@@ -28,3 +29,6 @@ speech_to_text:
 text_to_speech:
   - pico2wave:
       language: "fr-FR"
+  - voxygen:
+      language: "fr"
+      voice: "moussa"

+ 2 - 2
tts/pico2wave/pico2wave.py

@@ -8,10 +8,10 @@ AUDIO_CHANNEL = 1
 AUDIO_BUFFER = 2048
 
 
-def say(words):
+def say(words=None, language=None):
     temp_file = "/tmp/temp.wav"
     devnull = open("/dev/null", "w")
-    subprocess.check_output(["/usr/bin/pico2wave", "-l=fr-FR", "-w=%s" % temp_file, words], stderr=devnull)
+    subprocess.check_output(["/usr/bin/pico2wave", "-l=%s" % language, "-w=%s" % temp_file, words], stderr=devnull)
     AudioPlayer.play_audio(temp_file)
     devnull.close()
 

+ 0 - 5
tts/voxygen/voxygen.py

@@ -28,11 +28,6 @@ VOXYGEN_TIMEOUT_SEC = 30
 CACHE_PATH = "/tmp/jarvis/tts/voxygen"
 CACHE_EXTENSION = ".tts"
 
-AUDIO_FREQUENCY = 16000
-AUDIO_SIZE = -16
-AUDIO_CHANNEL = 1
-AUDIO_BUFFER = 2048
-
 
 def say(words=None, voice=None, language=VOXYGEN_LANGUAGES_DEFAULT, cache=True):
     voice = get_voice(voice, language)