def augment_dataset(cfg, dataset) -> list:
    """Augment dataset with formant_shift, pitch_shift, time_stretch, equalizer

    Args:
        cfg (dict): configuration
        dataset (str): dataset name

    Returns:
        list: augmented dataset names
    """
    # load metadata
    dataset_path = os.path.join(cfg.preprocess.processed_dir, dataset)
    split = ["train", "test"] if "eval" not in dataset else ["test"]
    augment_datasets = []
    aug_types = [
        "formant_shift" if cfg.preprocess.use_formant_shift else None,
        "pitch_shift" if cfg.preprocess.use_pitch_shift else None,
        "time_stretch" if cfg.preprocess.use_time_stretch else None,
        "equalizer" if cfg.preprocess.use_equalizer else None,
    ]
    aug_types = filter(None, aug_types)
    for aug_type in aug_types:
        print("Augmenting {} with {}...".format(dataset, aug_type))
        new_dataset = dataset + "_" + aug_type
        augment_datasets.append(new_dataset)
        new_dataset_path = os.path.join(cfg.preprocess.processed_dir, new_dataset)

        for dataset_type in split:
            metadata_path = os.path.join(dataset_path, "{}.json".format(dataset_type))
            augmented_metadata = []
            new_metadata_path = os.path.join(
                new_dataset_path, "{}.json".format(dataset_type)
            )
            os.makedirs(new_dataset_path, exist_ok=True)
            new_dataset_wav_dir = os.path.join(new_dataset_path, "wav")
            os.makedirs(new_dataset_wav_dir, exist_ok=True)

            if has_existed(new_metadata_path):
                continue

            with open(metadata_path, "r") as f:
                metadata = json.load(f)

            for utt in tqdm(metadata):
                original_wav_path = utt["Path"]
                original_wav, sr = torchaudio.load(original_wav_path)
                new_wav = wav_manipulation(original_wav, sr, aug_type=aug_type)
                new_wav_path = os.path.join(new_dataset_wav_dir, utt["Uid"] + ".wav")
                torchaudio.save(new_wav_path, new_wav, sr)
                new_utt = {
                    "Dataset": utt["Dataset"] + "_" + aug_type,
                    "index": utt["index"],
                    "Singer": utt["Singer"],
                    "Uid": utt["Uid"],
                    "Path": new_wav_path,
                    "Duration": utt["Duration"],
                }
                augmented_metadata.append(new_utt)
            new_metadata_path = os.path.join(
                new_dataset_path, "{}.json".format(dataset_type)
            )
            with open(new_metadata_path, "w") as f:
                json.dump(augmented_metadata, f, indent=4, ensure_ascii=False)
    return augment_datasets
Augment dataset with formant_shift, pitch_shift, time_stretch, equalizer

Args:
cfg (dict): configuration
dataset (str): dataset name

Returns:
list: augmented dataset names
processors/data_augment.py