Browse Source

[Feature] VoiceRSS with Doc

monf 8 years ago
parent
commit
01099efa81
5 changed files with 53 additions and 34 deletions
  1. 1 1
      settings.yml
  2. 6 5
      tts/acapela/README.md
  3. 4 5
      tts/googletts/README.md
  4. 8 0
      tts/voicerss/README.md
  5. 34 23
      tts/voicerss/voicerss.py

+ 1 - 1
settings.yml

@@ -48,7 +48,7 @@ speech_to_text:
 # Text to speech
 # ---------------------------
 # This is the default TTS that will be used by Kalliope to talk.
-default_text_to_speech: "googletts"
+default_text_to_speech: "voicerss"
 # where we store generated audio files from TTS engine to reuse them
 cache_path: "/tmp/kalliope_tts_cache"
 

+ 6 - 5
tts/acapela/README.md

@@ -2,11 +2,12 @@
 
 this TTS is based on the [Acapela engine](http://www.acapela-group.com/)
 
-| Parameters | Required | Default | Choices                                                        | Comment                                                                     |
-|------------|----------|---------|----------------------------------------------------------------|-----------------------------------------------------------------------------|
-| language   | YES      |         | 34 languages (http://www.acapela-group.com/voices/repertoire/) | Language are corresponding to an id plz check the note beside to find yours |
-| voice      | YES      |         | multiple and depending of the language                         | Check available names on the web site                                       |
-| cache      | No       | TRUE    | True / False                                                   | True if you want to use the cache with this TTS                             |
+| Parameters | Required | Default | Choices                                                                            | Comment                                                                     |
+|------------|----------|---------|------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
+| language   | YES      |         | 34 languages (http://www.acapela-group.com/voices/repertoire/), example: "sonid15" | Language are corresponding to an id plz check the note beside to find yours |
+| voice      | YES      |         | multiple and depending of the language                                             | Check available names on the web site                                       |
+| cache      | No       | TRUE    | True / False                                                                       | True if you want to use the cache with this TTS                             |
+
 
 #### Notes
 

+ 4 - 5
tts/googletts/README.md

@@ -1,8 +1,7 @@
 ### Googletts
 
 this TTS is based on the [Google translate engine](http://translate.google.com/)
-
-| Parameters | Required | Default | Choices                                                                      | Comment                                                                                                    |
-|------------|----------|---------|------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
-| language   | YES      |         | 103 languages (http://translate.google.com/about/intl/en_ALL/languages.html) | Language are identified with their ISO_639-1 codes (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) |
-| cache      | No       | TRUE    | True / False                                                                 | True if you want to use the cache with this TTS                                                            |
+| Parameters | Required | Default | Choices                                                                                     | Comment                                                                                                    |
+|------------|----------|---------|---------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
+| language   | YES      |         | 103 languages (http://translate.google.com/about/intl/en_ALL/languages.html), example: "fr" | Language are identified with their ISO_639-1 codes (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) |
+| cache      | No       | TRUE    | True / False                                                                                | True if you want to use the cache with this TTS                                                            |

+ 8 - 0
tts/voicerss/README.md

@@ -0,0 +1,8 @@
+### Voicerss
+
+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 |

+ 34 - 23
tts/voicerss/voicerss.py

@@ -1,37 +1,48 @@
+import requests
+from core import FileManager
+from core.TTS.TTSModule import TTSModule, FailToLoadSoundFile
 import logging
 
-from core import AudioPlayer
-from tts import TTS
-
 logging.basicConfig()
 logger = logging.getLogger("kalliope")
 
+TTS_URL = "http://www.voicerss.org/controls/speech.ashx"
+TTS_CONTENT_TYPE = "audio/mpeg"
+TTS_TIMEOUT_SEC = 30
+
+
+class Voicerss(TTSModule):
+    def __init__(self, **kwargs):
+        super(Voicerss, self).__init__(**kwargs)
 
-class Voicerss(TTS):
-    TTS_LANGUAGES_DEFAULT = 'fr-fr'
-    TTS_URL = "http://www.voicerss.org/controls/speech.ashx"
-    TTS_CONTENT_TYPE = "audio/mpeg"
-    TTS_TIMEOUT_SEC = 30
+    def say(self, words):
 
-    def __init__(self):
-        TTS.__init__(self)
+        self.generate_and_play(words, self._generate_audio_file)
 
-    def say(self, words=None, language=TTS_LANGUAGES_DEFAULT, cache=True):
-        self.say_generic(cache, language, words, self.get_audio_voicerss, AudioPlayer.PLAYER_MP3, AudioPlayer.AUDIO_MP3_44100_FREQUENCY)
+    def _generate_audio_file(self):
 
-    def get_audio_voicerss(self, **kwargs):
-        words = kwargs.get('words', None)
-        cache = kwargs.get('cache', None)
-        file_path = kwargs.get('file_path', None)
-        language = kwargs.get('language', None)
-        payload = Voicerss.get_payload(language, words)
+        # Prepare payload
+        payload = self.get_payload()
 
-        return TTS.get_audio(file_path, cache, payload, self.TTS_URL)
+        # getting the audio
+        r = requests.get(TTS_URL, params=payload, stream=True, timeout=TTS_TIMEOUT_SEC)
+        content_type = r.headers['Content-Type']
 
-    @staticmethod
-    def get_payload(language, words):
+        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")
+
+        # OK we get the audio we can write the sound file
+        FileManager.write_in_file(self.file_path, r.content)
+
+    def get_payload(self):
         return {
-            "src": words,
-            "hl": language,
+            "src": self.words,
+            "hl": self.language,
             "c": "mp3"
         }
+