Browse Source

[Feature] #395 update the voicerss tts

using the official python lib wrapper
ThiBuff 7 years ago
parent
commit
792dd67f0b

+ 1 - 0
install/files/python_requirements.txt

@@ -25,3 +25,4 @@ pyalsaaudio>=0.8.4
 RPi.GPIO>=0.6.3
 sox>=1.3.0
 paho-mqtt>=1.3.0
+voicerss_tts>=1.0.3

+ 2 - 1
kalliope/settings.yml

@@ -58,7 +58,7 @@ speech_to_text:
 # Text to speech
 # ---------------------------
 # This is the default TTS that will be used by Kalliope to talk.
-default_text_to_speech: "pico2wave"
+default_text_to_speech: "voicerss"
 # where we store generated audio files from TTS engine to reuse them
 cache_path: "/tmp/kalliope_tts_cache"
 
@@ -77,6 +77,7 @@ text_to_speech:
       cache: True
   - voicerss:
       language: "fr-fr"
+      key: "API_Key"
       cache: True
   - watson:
       username: "me"

+ 20 - 4
kalliope/tts/voicerss/README.md

@@ -2,7 +2,23 @@
 
 This TTS is based on the [VoiceRSS engine](http://www.voicerss.org/)
 
-| Parameters | Required | Default | Choices                                                                          | Comment                                         |
-|------------|----------|---------|----------------------------------------------------------------------------------|-------------------------------------------------|
-| language   | YES      |         | 26 languages (http://www.voicerss.org/api/documentation.aspx), example : "fr-fr" | Languages are identified by the LCID string     |
-| cache      | No       | TRUE    | True / False                                                                     | True if you want to use the cache with this TTS |
+Official Documentation : http://www.voicerss.org/api/documentation.aspx
+
+| Parameters   | Required | Default              | Choices                                                                          | Comment                                         |
+|--------------|----------|----------------------|----------------------------------------------------------------------------------|-------------------------------------------------|
+| language     | YES      |                      | 26 languages (http://www.voicerss.org/api/documentation.aspx), example : "fr-fr" | Languages are identified by the LCID string     |
+| key          | YES      |                      |                                                                                  | register in the official website to get API key |
+| rate         | NO       | 0                    |  any int                                                                         | Audio Rate                                      |
+| codec        | NO       | 'MP3'                | 'MP3', 'WAV', 'AAC', 'OGG', 'CAF'                                                | Audio Codecs                                    |
+| audio_format | NO       | '44khz_16bit_stereo' | 51 choices (http://www.voicerss.org/api/documentation.aspx), '8khz_8bit_mono'    | Audio formats                                   |
+| ssml         | NO       |  False               | True / False                                                                     | True if you want ssml (only upgraded plans)     |
+| base64       | NO       |  False               | True / False                                                                     | True if you want base64                         |
+| ssl          | NO       |  False               | True / False                                                                     | True if you want ssl                            |
+| cache        | NO       |  True                | True / False                                                                     | True if you want to use the cache with this TTS |
+
+### Notes
+
+limitations : 100KB per request
+
+The Free edition is limited to 350 daily requests. 
+Possibility to [upgrade the plan](http://www.voicerss.org/personel/upgrade.aspx)

+ 22 - 30
kalliope/tts/voicerss/voicerss.py

@@ -2,6 +2,7 @@ import requests
 from kalliope.core import FileManager
 from kalliope.core.TTS.TTSModule import TTSModule, FailToLoadSoundFile, MissingTTSParameter
 import logging
+from voicerss_tts.voicerss_tts import TextToSpeech
 
 logging.basicConfig()
 logger = logging.getLogger("kalliope")
@@ -14,6 +15,14 @@ TTS_TIMEOUT_SEC = 30
 class Voicerss(TTSModule):
     def __init__(self, **kwargs):
         super(Voicerss, self).__init__(**kwargs)
+
+        self.key = kwargs.get('key', None)
+        self.rate = kwargs.get('rate', 0)
+        self.codec = kwargs.get('codec', 'MP3')
+        self.audio_format = kwargs.get('audio_format', '44khz_16bit_stereo')
+        self.ssml = kwargs.get('ssml', False)
+        self.base64 = kwargs.get('base64', False)
+        self.ssl = kwargs.get('ssl', False)
         self._check_parameters()
 
     def say(self, words):
@@ -30,8 +39,8 @@ class Voicerss(TTSModule):
 
                .. raises:: MissingTTSParameterException
         """
-        if self.language == "default" or self.language is None:
-            raise MissingTTSParameter("[voicerss] Missing parameters, check documentation !")
+        if self.language == "default" or self.language is None or self.key is None:
+            raise MissingTTSParameter("[voicerss] Missing mandatory parameters, check documentation !")
         return True
 
     def _generate_audio_file(self):
@@ -41,33 +50,16 @@ class Voicerss(TTSModule):
 
         .. raises:: FailToLoadSoundFile
         """
-        # Prepare payload
-        payload = self.get_payload()
-
-        # getting the audio
-        r = requests.get(TTS_URL, params=payload, stream=True, timeout=TTS_TIMEOUT_SEC)
-        content_type = r.headers['Content-Type']
-
-        logger.debug("Voicerss : Trying to get url: %s response code: %s and content-type: %s",
-                     r.url,
-                     r.status_code,
-                     content_type)
-        # Verify the response status code and the response content type
-        if r.status_code != requests.codes.ok or content_type != TTS_CONTENT_TYPE:
-            raise FailToLoadSoundFile("Voicerss : Fail while trying to remotely access the audio file")
+        voicerss = TextToSpeech(
+             api_key=self.key,
+             text= self.words,
+             language=self.language,
+             rate=self.rate,
+             codec=self.codec,
+             audio_format=self.audio_format,
+             ssml=self.ssml,
+             base64=self.base64,
+             ssl=self.ssl)
 
         # OK we get the audio we can write the sound file
-        FileManager.write_in_file(self.file_path, r.content)
-
-    def get_payload(self):
-        """
-        Generic method used load the payload used to access the remote api
-
-        :return: Payload to use to access the remote api
-        """
-
-        return {
-            "src": self.words,
-            "hl": self.language,
-            "c": "mp3"
-        }
+        FileManager.write_in_file(self.file_path, voicerss.speech)

+ 2 - 1
setup.py

@@ -92,7 +92,8 @@ setup(
         'pyalsaaudio>=0.8.4',
         'RPi.GPIO>=0.6.3',
         'sox>=1.3.0',
-        'paho-mqtt>=1.3.0'
+        'paho-mqtt>=1.3.0',
+        'voicerss_tts>=1.0.3'
     ],