synthesizer_preprocess_audio.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from synthesizer.preprocess import preprocess_dataset
  2. from synthesizer.hparams import hparams
  3. from utils.argutils import print_args
  4. from pathlib import Path
  5. import argparse
  6. if __name__ == "__main__":
  7. parser = argparse.ArgumentParser(
  8. description="Preprocesses audio files from datasets, encodes them as mel spectrograms "
  9. "and writes them to the disk. Audio files are also saved, to be used by the "
  10. "vocoder for training.",
  11. formatter_class=argparse.ArgumentDefaultsHelpFormatter
  12. )
  13. parser.add_argument("datasets_root", type=Path, help=\
  14. "Path to the directory containing your LibriSpeech/TTS datasets.")
  15. parser.add_argument("-o", "--out_dir", type=Path, default=argparse.SUPPRESS, help=\
  16. "Path to the output directory that will contain the mel spectrograms, the audios and the "
  17. "embeds. Defaults to <datasets_root>/SV2TTS/synthesizer/")
  18. parser.add_argument("-n", "--n_processes", type=int, default=4, help=\
  19. "Number of processes in parallel.")
  20. parser.add_argument("-s", "--skip_existing", action="store_true", help=\
  21. "Whether to overwrite existing files with the same name. Useful if the preprocessing was "
  22. "interrupted.")
  23. parser.add_argument("--hparams", type=str, default="", help=\
  24. "Hyperparameter overrides as a comma-separated list of name-value pairs")
  25. parser.add_argument("--no_alignments", action="store_true", help=\
  26. "Use this option when dataset does not include alignments\
  27. (these are used to split long audio files into sub-utterances.)")
  28. parser.add_argument("--datasets_name", type=str, default="LibriSpeech", help=\
  29. "Name of the dataset directory to process.")
  30. parser.add_argument("--subfolders", type=str, default="train-clean-100,train-clean-360", help=\
  31. "Comma-separated list of subfolders to process inside your dataset directory")
  32. args = parser.parse_args()
  33. # Process the arguments
  34. if not hasattr(args, "out_dir"):
  35. args.out_dir = args.datasets_root.joinpath("SV2TTS", "synthesizer")
  36. # Create directories
  37. assert args.datasets_root.exists()
  38. args.out_dir.mkdir(exist_ok=True, parents=True)
  39. # Preprocess the dataset
  40. print_args(args, parser)
  41. args.hparams = hparams.parse(args.hparams)
  42. preprocess_dataset(**vars(args))