From 27837b270b260cb4820d8302516f2857e0ebd871 Mon Sep 17 00:00:00 2001 From: Heiko J Schick Date: Tue, 30 Aug 2022 20:42:27 +0200 Subject: [PATCH] Added parsing of command line arguments --- tts.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tts.py b/tts.py index d1042ab..9be9262 100644 --- a/tts.py +++ b/tts.py @@ -4,6 +4,7 @@ # — https://huggingface.co/facebook/fastspeech2-en-ljspeech # — https://github.com/AI-Guru/arxiv-reader +import argparse from fairseq.checkpoint_utils import load_model_ensemble_and_task_from_hf_hub from fairseq.models.text_to_speech.hub_interface import TTSHubInterface import scipy @@ -15,6 +16,12 @@ def main(): Defined starting point of source code. """ + # Parsing command line arguments + parser = argparse.ArgumentParser(description='Convert teext to speech.') + parser.add_argument('-i','--input', help='Input filename', required=True) + parser.add_argument('-o','--output', help='Output filename', required=True) + args = vars(parser.parse_args()) + models, cfg, task = load_model_ensemble_and_task_from_hf_hub( "facebook/fastspeech2-en-ljspeech", arg_overrides={"vocoder": "hifigan", "fp16": False} @@ -28,7 +35,7 @@ def main(): sentences = [] # Read input file - with open(f"input.txt", "r") as f: + with open(args['input'], "r") as f: lines = f.readlines() # Convert to sentences @@ -60,7 +67,7 @@ def main(): full_wave_file.extend(wav) full_wave_file = np.array(full_wave_file, dtype=np.float32) - scipy.io.wavfile.write("test.wav", rate, full_wave_file) + scipy.io.wavfile.write(args['output'], rate, full_wave_file) if __name__ == "__main__": main() \ No newline at end of file