vocoder_preprocess.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import argparse
  2. import os
  3. from pathlib import Path
  4. from synthesizer.hparams import hparams
  5. from synthesizer.synthesize import run_synthesis
  6. from utils.argutils import print_args
  7. if __name__ == "__main__":
  8. class MyFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
  9. pass
  10. parser = argparse.ArgumentParser(
  11. description="Creates ground-truth aligned (GTA) spectrograms from the vocoder.",
  12. formatter_class=MyFormatter
  13. )
  14. parser.add_argument("datasets_root", type=Path, help=\
  15. "Path to the directory containing your SV2TTS directory. If you specify both --in_dir and "
  16. "--out_dir, this argument won't be used.")
  17. parser.add_argument("-s", "--syn_model_fpath", type=Path,
  18. default="saved_models/default/synthesizer.pt",
  19. help="Path to a saved synthesizer")
  20. parser.add_argument("-i", "--in_dir", type=Path, default=argparse.SUPPRESS, help= \
  21. "Path to the synthesizer directory that contains the mel spectrograms, the wavs and the "
  22. "embeds. Defaults to <datasets_root>/SV2TTS/synthesizer/.")
  23. parser.add_argument("-o", "--out_dir", type=Path, default=argparse.SUPPRESS, help= \
  24. "Path to the output vocoder directory that will contain the ground truth aligned mel "
  25. "spectrograms. Defaults to <datasets_root>/SV2TTS/vocoder/.")
  26. parser.add_argument("--hparams", default="", help=\
  27. "Hyperparameter overrides as a comma-separated list of name=value pairs")
  28. parser.add_argument("--cpu", action="store_true", help=\
  29. "If True, processing is done on CPU, even when a GPU is available.")
  30. args = parser.parse_args()
  31. print_args(args, parser)
  32. modified_hp = hparams.parse(args.hparams)
  33. if not hasattr(args, "in_dir"):
  34. args.in_dir = args.datasets_root / "SV2TTS" / "synthesizer"
  35. if not hasattr(args, "out_dir"):
  36. args.out_dir = args.datasets_root / "SV2TTS" / "vocoder"
  37. if args.cpu:
  38. # Hide GPUs from Pytorch to force CPU processing
  39. os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
  40. run_synthesis(args.in_dir, args.out_dir, args.syn_model_fpath, modified_hp)