Skip to content

Commit

Permalink
hubconf.py and load .models.json from the defualt location by mange.py
Browse files Browse the repository at this point in the history
  • Loading branch information
erogol committed Mar 8, 2021
1 parent e9364a4 commit bbea6a0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
26 changes: 26 additions & 0 deletions TTS/hubconf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
dependencies = ['torch', 'gdown']
import torch
import os
import zipfile

from TTS.utils.generic_utils import get_user_data_dir
from TTS.utils.synthesizer import Synthesizer
from TTS.utils.manage import ModelManager



def tts(model_name='tts_models/en/ljspeech/tacotron2-DCA', vocoder_name='vocoder_models/en/ljspeech/mulitband-melgan', pretrained=True):
manager = ModelManager()

model_path, config_path = manager.download_model(model_name)
vocoder_path, vocoder_config_path = manager.download_model(vocoder_name)

# create synthesizer
synthesizer = Synthesizer(model_path, config_path, vocoder_path, vocoder_config_path)
return synthesizer


if __name__ == '__main__':
# synthesizer = torch.hub.load('/data/rw/home/projects/TTS/TTS', 'tts', source='local')
synthesizer = torch.hub.load('mozilla/TTS:hub_conf', 'tts', source='github')
synthesizer.tts("This is a test!")
16 changes: 11 additions & 5 deletions TTS/utils/manage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import json
import gdown
from pathlib import Path
import os
from pathlib import Path

from TTS.utils.io import load_config
import gdown
from TTS.utils.generic_utils import get_user_data_dir
from TTS.utils.io import load_config


class ModelManager(object):
"""Manage TTS models defined in .models.json.
Expand All @@ -17,12 +18,17 @@ class ModelManager(object):
Args:
models_file (str): path to .model.json
"""
def __init__(self, models_file):
def __init__(self, models_file=None):
super().__init__()
self.output_prefix = get_user_data_dir('tts')
self.url_prefix = "https://drive.google.com/uc?id="
self.models_dict = None
self.read_models_file(models_file)
if models_file is not None:
self.read_models_file(models_file)
else:
# try the default location
path = Path(__file__).parent / "../.models.json"
self.read_models_file(path)

def read_models_file(self, file_path):
"""Read .models.json as a dict
Expand Down

0 comments on commit bbea6a0

Please sign in to comment.