|
@@ -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)
|