From 31cb602e07612169386085af506bc42345cf8857 Mon Sep 17 00:00:00 2001 From: James Betker Date: Sun, 10 Apr 2022 23:19:15 -0600 Subject: [PATCH] support presets for generation --- api.py | 15 +++++++++++++++ eval_multiple.py | 10 +++------- read.py | 5 +++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/api.py b/api.py index 55ec199..b1f3740 100644 --- a/api.py +++ b/api.py @@ -160,6 +160,21 @@ class TextToSpeech: self.vocoder.load_state_dict(torch.load('.models/vocoder.pth')['model_g']) self.vocoder.eval(inference=True) + def tts_with_preset(self, text, voice_samples, preset='intelligible', **kwargs): + """ + Calls TTS with one of a set of preset generation parameters. Options: + 'intelligible': Maximizes the probability of understandable words at the cost of diverse voices, intonation and prosody. + 'realistic': Increases the diversity of spoken voices and improves realism of vocal characteristics at the cost of intelligibility. + 'mid': Somewhere between 'intelligible' and 'realistic'. + """ + presets = { + 'intelligible': {'temperature': .5, 'length_penalty': 2.0, 'repetition_penalty': 2.0, 'top_p': .5, 'diffusion_iterations': 100, 'cond_free': True, 'cond_free_k': .7, 'diffusion_temperature': .7}, + 'mid': {'temperature': .7, 'length_penalty': 1.0, 'repetition_penalty': 2.0, 'top_p': .7, 'diffusion_iterations': 100, 'cond_free': True, 'cond_free_k': 1.5, 'diffusion_temperature': .8}, + 'realistic': {'temperature': .9, 'length_penalty': 1.0, 'repetition_penalty': 1.3, 'top_p': .9, 'diffusion_iterations': 100, 'cond_free': True, 'cond_free_k': 2, 'diffusion_temperature': 1}, + } + kwargs.update(presets[preset]) + return self.tts(text, voice_samples, **kwargs) + def tts(self, text, voice_samples, k=1, # autoregressive generation parameters follow num_autoregressive_samples=512, temperature=.5, length_penalty=1, repetition_penalty=2.0, top_p=.5, diff --git a/eval_multiple.py b/eval_multiple.py index 99e1eae..b772f8a 100644 --- a/eval_multiple.py +++ b/eval_multiple.py @@ -7,7 +7,7 @@ from utils.audio import load_audio if __name__ == '__main__': fname = 'Y:\\libritts\\test-clean\\transcribed-brief-w2v.tsv' - outpath = 'D:\\tmp\\tortoise-tts-eval\\compare_vocoders' + outpath = 'D:\\tmp\\tortoise-tts-eval\\eval_new_autoregressive' outpath_real = 'D:\\tmp\\tortoise-tts-eval\\real' os.makedirs(outpath, exist_ok=True) @@ -24,16 +24,12 @@ if __name__ == '__main__': path = os.path.join(os.path.dirname(fname), line[1]) cond_audio = load_audio(path, 22050) torchaudio.save(os.path.join(outpath_real, os.path.basename(line[1])), cond_audio, 22050) - sample, sample2 = tts.tts(transcript, [cond_audio, cond_audio], num_autoregressive_samples=512, k=1, + sample = tts.tts(transcript, [cond_audio, cond_audio], num_autoregressive_samples=512, k=1, repetition_penalty=2.0, length_penalty=2, temperature=.5, top_p=.5, diffusion_temperature=.7, cond_free_k=2, diffusion_iterations=200) down = torchaudio.functional.resample(sample, 24000, 22050) - fout_path = os.path.join(outpath, 'old', os.path.basename(line[1])) - torchaudio.save(fout_path, down.squeeze(0), 22050) - - down = torchaudio.functional.resample(sample2, 24000, 22050) - fout_path = os.path.join(outpath, 'new', os.path.basename(line[1])) + fout_path = os.path.join(outpath, os.path.basename(line[1])) torchaudio.save(fout_path, down.squeeze(0), 22050) recorder.write(f'{transcript}\t{fout_path}\n') diff --git a/read.py b/read.py index f05060d..08841f0 100644 --- a/read.py +++ b/read.py @@ -48,9 +48,10 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('-textfile', type=str, help='A file containing the text to read.', default="data/riding_hood.txt") parser.add_argument('-voice', type=str, help='Use a preset conditioning voice (defined above). Overrides cond_path.', default='dotrice') - parser.add_argument('-num_samples', type=int, help='How many total outputs the autoregressive transformer should produce.', default=256) + parser.add_argument('-num_samples', type=int, help='How many total outputs the autoregressive transformer should produce.', default=512) parser.add_argument('-batch_size', type=int, help='How many samples to process at once in the autoregressive model.', default=16) parser.add_argument('-output_path', type=str, help='Where to store outputs.', default='results/longform/') + parser.add_argument('-generation_preset', type=str, help='Preset to use for generation', default='intelligible') args = parser.parse_args() os.makedirs(args.output_path, exist_ok=True) @@ -67,7 +68,7 @@ if __name__ == '__main__': for cond_path in cond_paths: c = load_audio(cond_path, 22050) conds.append(c) - gen = tts.tts(text, conds, num_autoregressive_samples=args.num_samples, temperature=.7, top_p=.7) + gen = tts.tts_with_preset(text, conds, preset=args.generation_preset, num_autoregressive_samples=args.num_samples) torchaudio.save(os.path.join(args.output_path, f'{j}.wav'), gen.squeeze(0).cpu(), 24000) priors.append(torchaudio.functional.resample(gen, 24000, 22050).squeeze(0))