2021-05-01 16:41:56 +00:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import torch
|
|
|
|
|
2021-05-15 21:48:31 +00:00
|
|
|
from tests import get_tests_input_path, get_tests_output_path, run_cli
|
2021-05-11 00:42:22 +00:00
|
|
|
from TTS.config import load_config
|
2021-05-15 21:48:31 +00:00
|
|
|
from TTS.tts.utils.generic_utils import setup_model
|
2021-05-04 23:45:07 +00:00
|
|
|
from TTS.tts.utils.text.symbols import phonemes, symbols
|
2021-05-01 16:41:56 +00:00
|
|
|
|
|
|
|
torch.manual_seed(1)
|
|
|
|
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
class TestExtractTTSSpectrograms(unittest.TestCase):
|
|
|
|
@staticmethod
|
|
|
|
def test_GlowTTS():
|
2021-05-04 23:45:07 +00:00
|
|
|
# set paths
|
|
|
|
config_path = os.path.join(get_tests_input_path(), "test_glow_tts.json")
|
2021-05-15 21:48:31 +00:00
|
|
|
checkpoint_path = os.path.join(get_tests_output_path(), "checkpoint_test.pth.tar")
|
|
|
|
output_path = os.path.join(get_tests_output_path(), "output_extract_tts_spectrograms/")
|
2021-05-04 23:45:07 +00:00
|
|
|
# load config
|
|
|
|
c = load_config(config_path)
|
2021-05-01 16:41:56 +00:00
|
|
|
# create model
|
2021-05-04 23:45:07 +00:00
|
|
|
num_chars = len(phonemes if c.use_phonemes else symbols)
|
|
|
|
model = setup_model(num_chars, 1, c, speaker_embedding_dim=None)
|
|
|
|
# save model
|
|
|
|
torch.save({"model": model.state_dict()}, checkpoint_path)
|
|
|
|
# run test
|
2021-05-15 21:48:31 +00:00
|
|
|
run_cli(
|
|
|
|
f'CUDA_VISIBLE_DEVICES="" python TTS/bin/extract_tts_spectrograms.py --config_path "{config_path}" --checkpoint_path "{checkpoint_path}" --output_path "{output_path}"'
|
|
|
|
)
|
2021-05-04 23:45:07 +00:00
|
|
|
run_cli(f'rm -rf "{output_path}" "{checkpoint_path}"')
|
2021-05-15 21:48:31 +00:00
|
|
|
|
2021-05-04 23:45:07 +00:00
|
|
|
@staticmethod
|
|
|
|
def test_Tacotron2():
|
|
|
|
# set paths
|
|
|
|
config_path = os.path.join(get_tests_input_path(), "test_tacotron2_config.json")
|
2021-05-15 21:48:31 +00:00
|
|
|
checkpoint_path = os.path.join(get_tests_output_path(), "checkpoint_test.pth.tar")
|
|
|
|
output_path = os.path.join(get_tests_output_path(), "output_extract_tts_spectrograms/")
|
2021-05-04 23:45:07 +00:00
|
|
|
# load config
|
|
|
|
c = load_config(config_path)
|
|
|
|
# create model
|
|
|
|
num_chars = len(phonemes if c.use_phonemes else symbols)
|
|
|
|
model = setup_model(num_chars, 1, c, speaker_embedding_dim=None)
|
|
|
|
# save model
|
|
|
|
torch.save({"model": model.state_dict()}, checkpoint_path)
|
|
|
|
# run test
|
2021-05-15 21:48:31 +00:00
|
|
|
run_cli(
|
|
|
|
f'CUDA_VISIBLE_DEVICES="" python TTS/bin/extract_tts_spectrograms.py --config_path "{config_path}" --checkpoint_path "{checkpoint_path}" --output_path "{output_path}"'
|
|
|
|
)
|
2021-05-04 23:45:07 +00:00
|
|
|
run_cli(f'rm -rf "{output_path}" "{checkpoint_path}"')
|
2021-05-15 21:48:31 +00:00
|
|
|
|
2021-05-01 16:41:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def test_Tacotron():
|
2021-05-04 23:45:07 +00:00
|
|
|
# set paths
|
|
|
|
config_path = os.path.join(get_tests_input_path(), "test_tacotron_config.json")
|
2021-05-15 21:48:31 +00:00
|
|
|
checkpoint_path = os.path.join(get_tests_output_path(), "checkpoint_test.pth.tar")
|
|
|
|
output_path = os.path.join(get_tests_output_path(), "output_extract_tts_spectrograms/")
|
2021-05-04 23:45:07 +00:00
|
|
|
# load config
|
|
|
|
c = load_config(config_path)
|
2021-05-01 16:41:56 +00:00
|
|
|
# create model
|
2021-05-04 23:45:07 +00:00
|
|
|
num_chars = len(phonemes if c.use_phonemes else symbols)
|
|
|
|
model = setup_model(num_chars, 1, c, speaker_embedding_dim=None)
|
|
|
|
# save model
|
|
|
|
torch.save({"model": model.state_dict()}, checkpoint_path)
|
|
|
|
# run test
|
2021-05-15 21:48:31 +00:00
|
|
|
run_cli(
|
|
|
|
f'CUDA_VISIBLE_DEVICES="" python TTS/bin/extract_tts_spectrograms.py --config_path "{config_path}" --checkpoint_path "{checkpoint_path}" --output_path "{output_path}"'
|
|
|
|
)
|
2021-05-04 23:45:07 +00:00
|
|
|
run_cli(f'rm -rf "{output_path}" "{checkpoint_path}"')
|