瀏覽代碼

add espeak tts to Kalliope core

Ultchad 7 年之前
父節點
當前提交
a9de8e9bef
共有 4 個文件被更改,包括 126 次插入1 次删除
  1. 2 1
      Docs/tts_list.md
  2. 65 0
      kalliope/tts/espeak/README.md
  3. 1 0
      kalliope/tts/espeak/__init__.py
  4. 58 0
      kalliope/tts/espeak/espeak.py

+ 2 - 1
Docs/tts_list.md

@@ -13,6 +13,7 @@ Core TTSs are already packaged with the installation of Kalliope an can be used
 | VoiceRSS  | [VoiceRSS](../kalliope/tts/voicerss/README.md)   | Cloud based |
 | Pico2wave | [Pico2wave](../kalliope/tts/pico2wave/README.md) | Self hosted |
 | ~~Voxygen~~ | ~~[Voxygen](../kalliope/tts/voxygen/README.md)~~ |~~Cloud based~~|
+| Espeak    | [Espeak](../kalliope/tts/espeak/README.md)       | Self hosted |
 
 ## Community TTS
 Community TTSs need to be installed manually.
@@ -21,7 +22,7 @@ To know how to install a community TTS, read the "Installation" section of the [
 
 | Name   | Description                                          | Type        |
 |--------|------------------------------------------------------|-------------|
-| Espeak | [Espeak](https://github.com/Ultchad/kalliope-espeak) | Self hosted |
+
 
 Wanna add your TTS in the list? Open [an issue](../../issues) with the link of your TTS or send a pull request to update the list directly.
 

+ 65 - 0
kalliope/tts/espeak/README.md

@@ -0,0 +1,65 @@
+# eSpeak
+
+## Synopsis
+
+This TTS is based on the eSpeak engine
+
+## Installation
+
+    kalliope install --git-url "https://github.com/Ultchad/kalliope-espeak.git"
+
+## Options
+
+| Parameters | Required | Default         | Choices                | Comment                                                                                       |
+|------------|----------|-----------------|------------------------|-----------------------------------------------------------|
+| voice      | yes      |                 | all voice installed    | see the full list with command "espeak --voices=LANGUAGE" |
+| variant    | no       |                 | all language installed | see the full list with command "espeak --voices=variant"  |
+| speed      | no       | 160             | 80 to 450              | Speed in words per minute                                 |
+| amplitude  | no       | 100             | 0 to 200               | Amplitude                                                 |
+| pitch      | no       | 50              | 0 to 99                | Pitch adjustment                                          |
+| path       | no       | /usr/bin/espeak | 0 to 99                | Path of espeak                                            |
+| cache      | no       | TRUE            |                        | True if you want to use the cache with this TTS           | 
+
+## Notes :
+
+To see the full list of language and voices:
+
+    espeak --voices
+
+To see the full list of voices:
+
+    espeak --voices=LANGUAGE
+    
+    # exemple:
+    
+    espeak --voices=fr
+    Pty Language Age/Gender VoiceName          File          Other Languages
+     5  fr-fr          M  french               fr            (fr 5)
+     7  fr             M  french-mbrola-1      mb/mb-fr1
+     7  fr             F  french-mbrola-4      mb/mb-fr4
+     5  fr-be          M  french-Belgium       europe/fr-be  (fr 8)
+     
+     # Configuration for "7  fr             M  french-mbrola-1      mb/mb-fr1"
+     voice: "mb-fr1"
+
+To see the full list of variant:
+
+    espeak --voices=variant
+    
+    # exemple:
+    
+    espeak --voices=variant
+    Pty Language Age/Gender VoiceName          File          Other Languages
+     5  variant        F  female2              !v/f2
+     5  variant        F  female3              !v/f3
+     5  variant        F  female4              !v/f4
+     5  variant        F  female5              !v/f5
+     5  variant        F  female_whisper       !v/whisperf
+     5  variant        -  klatt                !v/klatt
+     5  variant        -  klatt2               !v/klatt2
+     [...]
+     
+     # Configuration for "5  variant        F  female3              !v/f3"
+     # chose your language voice
+     voice: "fr"
+     variant: "f3"

+ 1 - 0
kalliope/tts/espeak/__init__.py

@@ -0,0 +1 @@
+from espeak import Espeak

+ 58 - 0
kalliope/tts/espeak/espeak.py

@@ -0,0 +1,58 @@
+from kalliope.core.TTS.TTSModule import TTSModule, MissingTTSParameter
+import logging
+import sys
+import subprocess
+
+logging.basicConfig()
+logger = logging.getLogger("kalliope")
+
+
+class Espeak(TTSModule):
+
+    def __init__(self, **kwargs):
+        super(Espeak, self).__init__(language="any", **kwargs)
+
+        # set parameter from what we receive from the settings
+        self.variant = kwargs.get('variant', None)
+        self.speed = str(kwargs.get('speed', '160'))
+        self.amplitude = str(kwargs.get('amplitude', '100'))
+        self.pitch = str(kwargs.get('pitch', '50'))
+        self.espeak_exec_path = kwargs.get('path', r'/usr/bin/espeak')
+
+        if self.voice == 'Default':
+            raise MissingTTSParameter("voice parameter is required by the eSpeak TTS")
+
+        # if voice = default, don't add voice option to espeak
+        if self.variant is None:
+            self.voice_and_variant = self.voice
+        else:
+            self.voice_and_variant = self.voice + '+' + self.variant
+
+    def say(self, words):
+        """
+        :param words: The sentence to say
+        """
+
+        self.generate_and_play(words, self._generate_audio_file)
+
+    def _generate_audio_file(self):
+        """
+        Generic method used as a Callback in TTSModule
+            - must provided the audio file and write it on the disk
+
+        .. raises:: FailToLoadSoundFile
+        """
+
+        options = {
+            'v': '-v' + self.voice_and_variant,
+            's': '-s' + self.speed,
+            'a': '-a' + self.amplitude,
+            'p': '-p' + self.pitch,
+            'w': '-w' + self.file_path
+        }
+
+        final_command = [self.espeak_exec_path, options['v'], options['s'], options['a'],
+                         options['p'], options['w'], self.words]
+
+        # generate the file with eSpeak
+        subprocess.call(final_command, stderr=sys.stderr)