TTS are independent projects so they can be developed under a github project. Anyone can clone them and place them under the TTS repository and reuse them or directly install them
Creating a new TTS must follow some rules:
The TTS inherits from the TTSModule coming from the Core.
from kalliope.core.TTS.TTSModule import TTSModule
class Pico2wave(TTSModule):
The TTS has a constructor init which is the entry point. The constructor has a **kwargs argument which is corresponding to the Dict of incoming variables:values defined either in the settings file.
The TTS must refer to its parent structure in the init by calling the super of TTSModule.
def __init__(self, **kwargs):
super(Pico2wave, self).__init__(**kwargs)
The TTS must implements a method _say(self, words) which must run call a method coming from the mother Class self.generate_and_play(words, callback).
Implement a callback in a separate method to run the audio. This callback is in charge to get the sound and save it on the disk. You can use our lib "FileManager.write_in_file(file_path, content)"
The module must use self.file_path
from the mother class to know the full path where to save the generated audio file. The file path is handled by the core in order to allow caching.
The generated audio file must be supported by Mplayer. Try to play a generated file with mplayer /path/to/the/generated_audio_file
Example of TTS structure
mytts/
├── __init__.py
├── mytts.py
├── dna.yml
├── install.yml
└── README.md
Example of TTS code
class Mytts(TTSModule):
def __init__(self, **kwargs):
super(Mytts, self).__init__(**kwargs)
# the args from the tts configuration
self.arg1 = kwargs.get('arg1', None)
self.arg2 = kwargs.get('arg2', None)
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 in self.file_path
.. raises:: FailToLoadSoundFile
"""
# -------------------
# - do amazing code to get the sound
# - save it to the disk using self.file_path
# - Attach the sound file path to the attribute : self.file_path = audio_file_path !
# -------------------