From 1f6a5310b812dedce72187c7fdf579ee51c148f3 Mon Sep 17 00:00:00 2001 From: James Betker Date: Fri, 7 Jan 2022 22:30:55 -0700 Subject: [PATCH] More fixes to use_gpt_tts --- codes/scripts/audio/gen/use_gpt_tts.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/codes/scripts/audio/gen/use_gpt_tts.py b/codes/scripts/audio/gen/use_gpt_tts.py index e871231b..a6fcc54e 100644 --- a/codes/scripts/audio/gen/use_gpt_tts.py +++ b/codes/scripts/audio/gen/use_gpt_tts.py @@ -1,4 +1,5 @@ import argparse +import os import random import torch @@ -9,6 +10,7 @@ from tokenizers import Tokenizer from data.audio.paired_voice_audio_dataset import CharacterTokenizer from data.audio.unsupervised_audio_dataset import load_audio +from data.audio.voice_tokenizer import VoiceBpeTokenizer from data.util import is_audio_file, find_files_of_type from models.tacotron2.text import text_to_sequence from scripts.audio.gen.speech_synthesis_utils import do_spectrogram_diffusion, \ @@ -86,14 +88,16 @@ if __name__ == '__main__': parser.add_argument('-diffusion_model_name', type=str, help='Name of the diffusion model in opt.', default='generator') parser.add_argument('-diffusion_model_path', type=str, help='Diffusion model checkpoint to load.', default='X:\\dlas\\experiments\\train_diffusion_vocoder_with_cond_new_dvae_full\\models\\6100_generator_ema.pth') parser.add_argument('-dvae_model_name', type=str, help='Name of the DVAE model in opt.', default='dvae') - parser.add_argument('-opt_gpt_tts', type=str, help='Path to options YAML file used to train the GPT-TTS model', default='X:\\dlas\\experiments\\train_gpt_unified_finetune_tts.yml') + parser.add_argument('-opt_gpt_tts', type=str, help='Path to options YAML file used to train the GPT-TTS model', default='X:\\dlas\\experiments\\train_gpt_tts_unified.yml') parser.add_argument('-gpt_tts_model_name', type=str, help='Name of the GPT TTS model in opt.', default='gpt') - parser.add_argument('-gpt_tts_model_path', type=str, help='GPT TTS model checkpoint to load.', default='X:\\dlas\\experiments\\train_gpt_unified_finetune_tts_libri_all_and_hifi_no_unsupervised\\models\\17500_gpt.pth') + parser.add_argument('-gpt_tts_model_path', type=str, help='GPT TTS model checkpoint to load.', default='X:\\dlas\\experiments\\train_gpt_tts_unified\\models\\30500_gpt.pth') parser.add_argument('-text', type=str, help='Text to speak.', default="I am a language model that has learned to speak.") parser.add_argument('-cond_path', type=str, help='Path to condioning sample.', default='') parser.add_argument('-cond_preset', type=str, help='Use a preset conditioning voice (defined above). Overrides cond_path.', default='libri_test') - parser.add_argument('-num_samples', type=int, help='How many outputs to produce.', default=1) + parser.add_argument('-num_samples', type=int, help='How many outputs to produce.', default=8) + parser.add_argument('-output_path', type=str, help='Where to store outputs.', default='../results/use_gpt_tts') args = parser.parse_args() + os.makedirs(args.output_path, exist_ok=True) # libritts_text = 'fall passed so quickly, there was so much going on around him, the tree quite forgot to look to himself.' print("Loading GPT TTS..") @@ -103,11 +107,9 @@ if __name__ == '__main__': gpt = load_model_from_config(preloaded_options=gpt_opt, model_name=args.gpt_tts_model_name, also_load_savepoint=False, load_path=args.gpt_tts_model_path, strict_load=False) print("Loading data..") - tokenizer = CharacterTokenizer() + tokenizer = VoiceBpeTokenizer('../experiments/bpe_lowercase_asr_256.json') text = torch.IntTensor(tokenizer.encode(args.text)).unsqueeze(0).cuda() text = F.pad(text, (0,1)) # This may not be necessary. - paired_text_length = gpt_opt['datasets']['train']['max_paired_text_length'] - assert paired_text_length >= text.shape[1] cond_path = args.cond_path if args.cond_preset is None else preselected_cond_voices[args.cond_preset] conds, cond_wav = load_conditioning(cond_path) @@ -132,4 +134,4 @@ if __name__ == '__main__': code = fix_autoregressive_output(codes[b], stop_token).unsqueeze(0) wav = do_spectrogram_diffusion(diffusion, dvae, diffuser, code, cond_wav, spectrogram_compression_factor=128, plt_spec=False) - torchaudio.save(f'gpt_tts_output_{b}.wav', wav.squeeze(0).cpu(), 11025) + torchaudio.save(os.path.join(args.output_path, f'gpt_tts_output_{b}.wav'), wav.squeeze(0).cpu(), 11025)