Преглед на файлове

Merge branch 'tts_refacto_acapela' into tts_refacto_nico

monf преди 8 години
родител
ревизия
372d6872af
променени са 4 файла, в които са добавени 30 реда и са изтрити 16 реда
  1. 12 4
      core/FileManager.py
  2. 1 2
      settings.yml
  3. 11 0
      tts/voxygen/README.md
  4. 6 10
      tts/voxygen/voxygen.py

+ 12 - 4
core/FileManager.py

@@ -1,7 +1,12 @@
+import logging
 import os
 import shutil
 
 
+logging.basicConfig()
+logger = logging.getLogger("kalliope")
+
+
 class FileManager:
     def __init__(self):
         pass
@@ -13,10 +18,13 @@ class FileManager:
 
     @staticmethod
     def write_in_file(file_path, content):
-        with open(file_path, "wb") as file_open:
-            file_open.write(content)
-            file_open.close()
-        return not FileManager.file_is_empty(file_path)
+        try:
+            with open(file_path, "wb") as file_open:
+                file_open.write(content)
+                file_open.close()
+            return not FileManager.file_is_empty(file_path)
+        except IOError as e:
+            logger.error("I/O error(%s): %s", e.errno, e.strerror)
 
     @staticmethod
     def wipe_cache(cache_path):

+ 1 - 2
settings.yml

@@ -61,8 +61,7 @@ text_to_speech:
       language: "fr-FR"
       cache: True
   - voxygen:
-      language: "fr"
-      voice: "Fabienne"
+      voice: "Agnes"
       cache: True
   - acapela:
       language: "sonid15"

+ 11 - 0
tts/voxygen/README.md

@@ -0,0 +1,11 @@
+### Voxygen
+
+This TTS is based on the demo of the [Voxygen engine](https://www.voxygen-group.com/)
+
+| Parameters | Required | Default | Choices                                                              | Comment                                                                                       |
+|------------|----------|---------|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
+| voice      | yes      |         | [see the full list](https://www.voxygen-group.com/). Example: "Emma" | Do not set any accent. For Example the voice "Agnès" will be "Agnes" is the settings.yml file |
+| cache      | no       | TRUE    |                                                                      | True if you want to use the cache with this TTS                                               |
+
+
+

+ 6 - 10
tts/voxygen/voxygen.py

@@ -16,7 +16,8 @@ TTS_CONTENT_TYPE = "audio/mpeg"
 class Voxygen(TTSModule):
 
     def __init__(self, **kwargs):
-        super(Voxygen, self).__init__(**kwargs)
+        # voxygen does'nt need a language. The name of the voice correspond to a lang
+        super(Voxygen, self).__init__(language="any", **kwargs)
 
         self.voice = kwargs.get('voice', None)
         if self.voice is None:
@@ -37,15 +38,10 @@ class Voxygen(TTSModule):
                      r.status_code,
                      content_type)
 
-        try:
-            if r.status_code == requests.codes.ok and content_type == TTS_CONTENT_TYPE:
-                return FileManager.write_in_file(self.file_path, r.content)
-            else:
-                return False
-        except IOError as e:
-            logger.error("I/O error(%s): %s", e.errno, e.strerror)
-        except ValueError:
-            logger.error("Could not convert data to an integer.")
+        if r.status_code == requests.codes.ok and content_type == TTS_CONTENT_TYPE:
+            FileManager.write_in_file(self.file_path, r.content)
+        else:
+            logger.debug("Unable to get a valid audio file. Returned code: %s" % r.status_code)
 
     @staticmethod
     def get_payload(voice, words):