2021-05-03 12:38:42 +00:00
|
|
|
dependencies = [
|
2021-07-07 23:30:21 +00:00
|
|
|
'torch', 'gdown', 'pysbd', 'gruut', 'anyascii', 'pypinyin', 'coqpit', 'mecab-python3', 'unidic-lite'
|
2021-05-18 13:07:25 +00:00
|
|
|
]
|
2021-01-29 15:00:33 +00:00
|
|
|
import torch
|
|
|
|
|
|
|
|
from TTS.utils.manage import ModelManager
|
2021-04-08 22:45:20 +00:00
|
|
|
from TTS.utils.synthesizer import Synthesizer
|
2021-01-29 15:00:33 +00:00
|
|
|
|
|
|
|
|
2021-05-03 12:38:42 +00:00
|
|
|
def tts(model_name='tts_models/en/ljspeech/tacotron2-DCA',
|
|
|
|
vocoder_name=None,
|
|
|
|
use_cuda=False):
|
2021-01-29 15:17:29 +00:00
|
|
|
"""TTS entry point for PyTorch Hub that provides a Synthesizer object to synthesize speech from a give text.
|
2021-01-29 15:00:33 +00:00
|
|
|
|
2021-01-29 15:17:29 +00:00
|
|
|
Example:
|
2021-03-05 01:50:38 +00:00
|
|
|
>>> synthesizer = torch.hub.load('coqui-ai/TTS', 'tts', source='github')
|
2021-01-29 15:17:29 +00:00
|
|
|
>>> wavs = synthesizer.tts("This is a test! This is also a test!!")
|
|
|
|
wavs - is a list of values of the synthesized speech.
|
2021-02-01 13:18:56 +00:00
|
|
|
|
2021-01-29 15:17:29 +00:00
|
|
|
Args:
|
|
|
|
model_name (str, optional): One of the model names from .model.json. Defaults to 'tts_models/en/ljspeech/tacotron2-DCA'.
|
2021-02-12 14:41:17 +00:00
|
|
|
vocoder_name (str, optional): One of the model names from .model.json. Defaults to 'vocoder_models/en/ljspeech/multiband-melgan'.
|
2021-01-29 15:17:29 +00:00
|
|
|
pretrained (bool, optional): [description]. Defaults to True.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
TTS.utils.synthesizer.Synthesizer: Synthesizer object wrapping both vocoder and tts models.
|
2021-02-01 13:18:56 +00:00
|
|
|
"""
|
2021-01-29 15:00:33 +00:00
|
|
|
manager = ModelManager()
|
2021-02-01 13:18:56 +00:00
|
|
|
|
2021-02-12 14:41:17 +00:00
|
|
|
model_path, config_path, model_item = manager.download_model(model_name)
|
2021-05-03 12:38:42 +00:00
|
|
|
vocoder_name = model_item[
|
|
|
|
'default_vocoder'] if vocoder_name is None else vocoder_name
|
2021-02-12 14:41:17 +00:00
|
|
|
vocoder_path, vocoder_config_path, _ = manager.download_model(vocoder_name)
|
2021-02-01 13:18:56 +00:00
|
|
|
|
2021-01-29 15:00:33 +00:00
|
|
|
# create synthesizer
|
2021-05-03 12:38:42 +00:00
|
|
|
synt = Synthesizer(tts_checkpoint=model_path,
|
|
|
|
tts_config_path=config_path,
|
|
|
|
vocoder_checkpoint=vocoder_path,
|
|
|
|
vocoder_config=vocoder_config_path,
|
|
|
|
use_cuda=use_cuda)
|
2021-02-01 13:18:56 +00:00
|
|
|
return synt
|
2021-01-29 15:00:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-05-03 12:38:42 +00:00
|
|
|
synthesizer = torch.hub.load('coqui-ai/TTS:dev', 'tts', source='github')
|
2021-02-05 13:10:43 +00:00
|
|
|
synthesizer.tts("This is a test!")
|