diff --git a/default_style.py b/default_style.py index bfe5698..9671db2 100644 --- a/default_style.py +++ b/default_style.py @@ -42,11 +42,17 @@ def save_neutral_vector(wav_dir: Union[Path, str], output_path: Union[Path, str] logger.info(f"Saved style config to {json_path}") -def save_styles_by_dirs(wav_dir: Union[Path, str], output_dir: Union[Path, str]): +def save_styles_by_dirs( + wav_dir: Union[Path, str], + output_dir: Union[Path, str], + config_path: Union[Path, str], + config_output_path: Union[Path, str], +): wav_dir = Path(wav_dir) output_dir = Path(output_dir) output_dir.mkdir(parents=True, exist_ok=True) - json_path = output_dir / "config.json" + config_path = Path(config_path) + config_output_path = Path(config_output_path) subdirs = [d for d in wav_dir.iterdir() if d.is_dir()] subdirs.sort() @@ -55,6 +61,7 @@ def save_styles_by_dirs(wav_dir: Union[Path, str], output_dir: Union[Path, str]) f"At least 2 subdirectories are required for generating style vectors with respect to them, found {len(subdirs)}." ) logger.info("Generating only neutral style vector instead.") + set_style_config(config_path, config_output_path) save_neutral_vector(wav_dir, output_dir) # First get mean of all for Neutral @@ -88,10 +95,10 @@ def save_styles_by_dirs(wav_dir: Union[Path, str], output_dir: Union[Path, str]) # Save style2id config to json style2id = {name: i for i, name in enumerate(names)} - with open(json_path, encoding="utf-8") as f: + with open(config_path, encoding="utf-8") as f: json_dict = json.load(f) json_dict["data"]["num_styles"] = len(names) json_dict["data"]["style2id"] = style2id - with open(json_path, "w", encoding="utf-8") as f: + with open(config_output_path, "w", encoding="utf-8") as f: json.dump(json_dict, f, indent=2, ensure_ascii=False) - logger.info(f"Saved style config to {json_path}") + logger.info(f"Saved style config to {config_output_path}") diff --git a/train_ms.py b/train_ms.py index 6f416e7..b699be2 100644 --- a/train_ms.py +++ b/train_ms.py @@ -195,6 +195,8 @@ def run(): default_style.save_styles_by_dirs( os.path.join(args.model, "wavs"), config.out_dir, + config_path=args.config, + config_output_path=os.path.join(config.out_dir, "config.json"), ) torch.manual_seed(hps.train.seed) diff --git a/train_ms_jp_extra.py b/train_ms_jp_extra.py index a7c2d89..84c0465 100644 --- a/train_ms_jp_extra.py +++ b/train_ms_jp_extra.py @@ -201,6 +201,8 @@ def run(): default_style.save_styles_by_dirs( os.path.join(args.model, "wavs"), config.out_dir, + config_path=args.config, + config_output_path=os.path.join(config.out_dir, "config.json"), ) torch.manual_seed(hps.train.seed)