File size: 4,786 Bytes
c968fc3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# Copyright (c) 2023 Amphion.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
For source datasets' standard samples
"""
from collections import defaultdict
import os
import json
SPEECH_DATASETS = ["vctk", "vctksample"]
GOLDEN_TEST_SAMPLES = defaultdict(list)
GOLDEN_TEST_SAMPLES["m4singer"] = [
"Alto-1_็พ้_0014",
"Bass-1_ๅๅนด_0008",
"Soprano-2_ๅๆก็ไฝ _0018",
"Tenor-5_็ฑ็ฌ็็ผ็_0010",
]
GOLDEN_TEST_SAMPLES["svcc"] = [
# IDF1
"IDF1_10030",
"IDF1_10120",
"IDF1_10140",
# IDM1
"IDM1_10001",
"IDM1_10030",
"IDM1_10120",
# CDF1
"CDF1_10030",
"CDF1_10120",
"CDF1_10140",
# CDM1
"CDM1_10001",
"CDM1_10030",
"CDM1_10120",
]
GOLDEN_TEST_SAMPLES["svcceval"] = [
# SF1
"SF1_30001",
"SF1_30002",
"SF1_30003",
# SM1
"SM1_30001",
"SM1_30002",
"SM1_30003",
]
GOLDEN_TEST_SAMPLES["popbutfy"] = [
"Female1#you_are_my_sunshine_Professional#0",
"Female4#Someone_Like_You_Professional#10",
"Male2#Lemon_Tree_Professional#12",
"Male5#can_you_feel_the_love_tonight_Professional#20",
]
GOLDEN_TEST_SAMPLES["opensinger"] = [
"Man_0_ๅคง้ฑผ_10",
"Man_21_ไธๅ
ซๆช_14",
"Woman_39_mojito_22",
"Woman_40_ๆ็ๆ็็ธ_12",
]
GOLDEN_TEST_SAMPLES["nus48e"] = [
"ADIZ_read#01#0000",
"MCUR_sing#10#0000",
"JLEE_read#08#0001",
"SAMF_sing#18#0001",
]
GOLDEN_TEST_SAMPLES["popcs"] = [
"ๆๅคฉไผๆดๅฅฝ_0004",
"ๆฌง่ฅๆ_0005",
"่ซๅฟ้ฃ_0006",
"้ๅฝข็็ฟ
่_0008",
]
GOLDEN_TEST_SAMPLES["kising"] = [
"421_0040",
"424_0013",
"431_0026",
]
GOLDEN_TEST_SAMPLES["csd"] = [
"en_004a_0001",
"en_042b_0006",
"kr_013a_0006",
"kr_045b_0004",
]
GOLDEN_TEST_SAMPLES["opera"] = [
"fem_01#neg_1#0000",
"fem_12#pos_3#0003",
"male_02#neg_1#0002",
"male_11#pos_2#0001",
]
GOLDEN_TEST_SAMPLES["lijian"] = [
"058็ๆ_0000",
"079็ป่ฑ_0000",
"120้ฅ่ฟ็ๅคฉ็ฉบๅบไธ_0000",
]
GOLDEN_TEST_SAMPLES["cdmusiceval"] = ["้ถๅ_ๆฎ้ๆๅ", "่ก็ด_็ป็ตๅฝฑไบบ็ๆ
ไนฆ"]
GOLDEN_TRAIN_SAMPLES = defaultdict(list)
def get_golden_samples_indexes(
dataset_name,
dataset_dir=None,
cfg=None,
split=None,
min_samples=5,
):
"""
# Get Standard samples' indexes
"""
if dataset_dir is None:
assert cfg is not None
dataset_dir = os.path.join(
cfg.OUTPUT_PATH,
"preprocess/{}_version".format(cfg.PREPROCESS_VERSION),
dataset_name,
)
assert split is not None
utt_file = os.path.join(dataset_dir, "{}.json".format(split))
with open(utt_file, "r", encoding="utf-8") as f:
samples = json.load(f)
if "train" in split:
golden_samples = GOLDEN_TRAIN_SAMPLES[dataset_name]
if "test" in split:
golden_samples = GOLDEN_TEST_SAMPLES[dataset_name]
res = []
for idx, utt in enumerate(samples):
if utt["Uid"] in golden_samples:
res.append(idx)
if dataset_name == "cdmusiceval":
if "_".join(utt["Uid"].split("_")[:2]) in golden_samples:
res.append(idx)
if len(res) == 0:
res = [i for i in range(min_samples)]
return res
def get_specific_singer_indexes(dataset_dir, singer_name, split):
utt_file = os.path.join(dataset_dir, "{}.json".format(split))
with open(utt_file, "r", encoding="utf-8") as f:
samples = json.load(f)
res = []
for idx, utt in enumerate(samples):
if utt["Singer"] == singer_name:
res.append(idx)
assert len(res) != 0
return res
def get_uids_and_wav_paths(
cfg, dataset, dataset_type="train", only_specific_singer=None, return_singers=False
):
dataset_dir = os.path.join(
cfg.OUTPUT_PATH, "preprocess/{}_version".format(cfg.PREPROCESS_VERSION), dataset
)
dataset_file = os.path.join(
dataset_dir, "{}.json".format(dataset_type.split("_")[-1])
)
with open(dataset_file, "r") as f:
utterances = json.load(f)
indexes = range(len(utterances))
if "golden" in dataset_type:
# golden_train or golden_test
indexes = get_golden_samples_indexes(
dataset, dataset_dir, split=dataset_type.split("_")[-1]
)
if only_specific_singer is not None:
indexes = get_specific_singer_indexes(
dataset_dir, only_specific_singer, dataset_type
)
uids = [utterances[i]["Uid"] for i in indexes]
wav_paths = [utterances[i]["Path"] for i in indexes]
singers = [utterances[i]["Singer"] for i in indexes]
if not return_singers:
return uids, wav_paths
else:
return uids, wav_paths, singers
|