Datasets:
Update NURC-SP_ENTOA_TTS.py
Browse files- NURC-SP_ENTOA_TTS.py +67 -156
NURC-SP_ENTOA_TTS.py
CHANGED
|
@@ -2,112 +2,44 @@ import csv
|
|
| 2 |
import datasets
|
| 3 |
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
}
|
| 9 |
|
| 10 |
-
|
| 11 |
-
"
|
| 12 |
"train": "automatic/train.csv",
|
| 13 |
}
|
| 14 |
|
| 15 |
_ARCHIVES = {
|
| 16 |
-
"
|
| 17 |
-
"
|
| 18 |
}
|
| 19 |
|
| 20 |
_PATH_TO_CLIPS = {
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
"validation_automatic": "automatic/validation",
|
| 24 |
-
"train_automatic": "automatic/train",
|
| 25 |
}
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
"""
|
| 31 |
-
import csv
|
| 32 |
-
from collections import defaultdict
|
| 33 |
-
|
| 34 |
-
# Store CSV paths
|
| 35 |
-
csv_paths = set()
|
| 36 |
-
|
| 37 |
-
with open(csv_path, "r") as f:
|
| 38 |
-
reader = csv.DictReader(f)
|
| 39 |
-
for row in reader:
|
| 40 |
-
# Store both the full path and filename
|
| 41 |
-
path = row.get("path") or row.get("file_path")
|
| 42 |
-
csv_paths.add(path)
|
| 43 |
-
csv_paths.add(path.split("/")[-1])
|
| 44 |
-
|
| 45 |
-
# Compare with archive paths
|
| 46 |
-
archive_paths = set()
|
| 47 |
-
matches = defaultdict(list)
|
| 48 |
-
|
| 49 |
-
for path, _ in archive_files:
|
| 50 |
-
archive_paths.add(path)
|
| 51 |
-
archive_paths.add(path.split("/")[-1])
|
| 52 |
-
|
| 53 |
-
# Check for matches
|
| 54 |
-
for csv_path in csv_paths:
|
| 55 |
-
if path.endswith(csv_path) or csv_path.endswith(path):
|
| 56 |
-
matches[path].append(csv_path)
|
| 57 |
-
|
| 58 |
-
print("=== Debug Report ===")
|
| 59 |
-
print(f"CSV Paths: {len(csv_paths)}")
|
| 60 |
-
print(f"Archive Paths: {len(archive_paths)}")
|
| 61 |
-
print(f"Matched Paths: {len(matches)}")
|
| 62 |
-
print("\nSample CSV paths:")
|
| 63 |
-
for path in list(csv_paths)[:5]:
|
| 64 |
-
print(f" {path}")
|
| 65 |
-
print("\nSample Archive paths:")
|
| 66 |
-
for path in list(archive_paths)[:5]:
|
| 67 |
-
print(f" {path}")
|
| 68 |
-
print("\nSample Matches:")
|
| 69 |
-
for archive_path, csv_paths in list(matches.items())[:5]:
|
| 70 |
-
print(f" Archive: {archive_path}")
|
| 71 |
-
print(f" CSV: {csv_paths}")
|
| 72 |
-
print()
|
| 73 |
-
|
| 74 |
-
return csv_paths, archive_paths, matches
|
| 75 |
-
|
| 76 |
-
class EntoaConfig(BuilderConfig):
|
| 77 |
-
def __init__(self, prompts_type="prosodic", **kwargs):
|
| 78 |
super().__init__(**kwargs)
|
| 79 |
self.prompts_type = prompts_type
|
| 80 |
|
| 81 |
-
|
|
|
|
| 82 |
BUILDER_CONFIGS = [
|
| 83 |
-
|
| 84 |
-
|
| 85 |
]
|
| 86 |
|
| 87 |
def _info(self):
|
| 88 |
-
|
| 89 |
-
features
|
| 90 |
-
{
|
| 91 |
-
"path": datasets.Value("string"),
|
| 92 |
-
"name": datasets.Value("string"),
|
| 93 |
-
"speaker": datasets.Value("string"),
|
| 94 |
-
"start_time": datasets.Value("string"),
|
| 95 |
-
"end_time": datasets.Value("string"),
|
| 96 |
-
"normalized_text": datasets.Value("string"),
|
| 97 |
-
"text": datasets.Value("string"),
|
| 98 |
-
"duration": datasets.Value("string"),
|
| 99 |
-
"type": datasets.Value("string"),
|
| 100 |
-
"year": datasets.Value("string"),
|
| 101 |
-
"gender": datasets.Value("string"),
|
| 102 |
-
"age_range": datasets.Value("string"),
|
| 103 |
-
"total_duration": datasets.Value("string"),
|
| 104 |
-
"quality": datasets.Value("string"),
|
| 105 |
-
"theme": datasets.Value("string"),
|
| 106 |
-
"audio": datasets.Audio(sampling_rate=16_000),
|
| 107 |
-
}
|
| 108 |
-
)
|
| 109 |
-
else: # automatic
|
| 110 |
-
features = datasets.Features(
|
| 111 |
{
|
| 112 |
"audio_name": datasets.Value("string"),
|
| 113 |
"file_path": datasets.Value("string"),
|
|
@@ -127,102 +59,81 @@ class EntoaDataset(GeneratorBasedBuilder):
|
|
| 127 |
"audio": datasets.Audio(sampling_rate=16_000),
|
| 128 |
}
|
| 129 |
)
|
| 130 |
-
|
| 131 |
|
| 132 |
def _split_generators(self, dl_manager):
|
| 133 |
-
prompts_urls =
|
| 134 |
-
archive = dl_manager.download(_ARCHIVES[self.config.name])
|
| 135 |
-
prompts_path = dl_manager.download(prompts_urls)
|
| 136 |
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
| 140 |
|
| 141 |
return [
|
| 142 |
SplitGenerator(
|
| 143 |
name=Split.VALIDATION,
|
| 144 |
gen_kwargs={
|
| 145 |
-
"prompts_path": prompts_path["
|
| 146 |
-
"path_to_clips": _PATH_TO_CLIPS[
|
| 147 |
-
"audio_files": dl_manager.iter_archive(archive),
|
| 148 |
-
}
|
| 149 |
),
|
| 150 |
SplitGenerator(
|
| 151 |
name=Split.TRAIN,
|
| 152 |
gen_kwargs={
|
| 153 |
"prompts_path": prompts_path["train"],
|
| 154 |
-
"path_to_clips": _PATH_TO_CLIPS[
|
| 155 |
-
"audio_files": dl_manager.iter_archive(archive),
|
| 156 |
-
}
|
| 157 |
),
|
| 158 |
]
|
| 159 |
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
| 164 |
-
csv_paths, archive_paths, matches = debug_path_matching(prompts_path, audio_files)
|
| 165 |
examples = {}
|
| 166 |
with open(prompts_path, "r") as f:
|
| 167 |
csv_reader = csv.DictReader(f)
|
| 168 |
for row in csv_reader:
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
"sex": row["sex"],
|
| 202 |
-
"age_range": row["age_range"],
|
| 203 |
-
"num_speakers": row["num_speakers"],
|
| 204 |
-
"speaker_id": row["speaker_id"],
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
id_ = 0
|
| 208 |
inside_clips_dir = False
|
| 209 |
-
|
| 210 |
for path, f in audio_files:
|
| 211 |
-
|
| 212 |
if path.startswith(path_to_clips):
|
| 213 |
inside_clips_dir = True
|
| 214 |
if path in examples:
|
| 215 |
-
# Debug: Match found
|
| 216 |
-
print(f"Match found for: {path}")
|
| 217 |
audio = {"path": path, "bytes": f.read()}
|
| 218 |
yield id_, {**examples[path], "audio": audio}
|
| 219 |
id_ += 1
|
| 220 |
-
else:
|
| 221 |
-
# Debug: No match for this file
|
| 222 |
-
print(f"No match for: {path}")
|
| 223 |
elif inside_clips_dir:
|
| 224 |
break
|
| 225 |
-
|
| 226 |
-
# Debug: Print total examples generated
|
| 227 |
-
print(f"Completed generating examples. Total examples: {id_}")
|
| 228 |
-
|
|
|
|
| 2 |
import datasets
|
| 3 |
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
| 4 |
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
_PROMPTS_URLS = {
|
| 8 |
+
"dev": "automatic/validation.csv",
|
| 9 |
+
"train": "automatic/train.csv",
|
| 10 |
}
|
| 11 |
|
| 12 |
+
_PROMPTS_FILTERED_URLS = {
|
| 13 |
+
"dev": "automatic/validation.csv",
|
| 14 |
"train": "automatic/train.csv",
|
| 15 |
}
|
| 16 |
|
| 17 |
_ARCHIVES = {
|
| 18 |
+
"dev": "automatic.tar.gz",
|
| 19 |
+
"train": "automatic.tar.gz",
|
| 20 |
}
|
| 21 |
|
| 22 |
_PATH_TO_CLIPS = {
|
| 23 |
+
"dev": "validation",
|
| 24 |
+
"train": "train",
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
+
|
| 28 |
+
class NurcSPConfig(BuilderConfig):
|
| 29 |
+
def __init__(self, prompts_type="original", **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
super().__init__(**kwargs)
|
| 31 |
self.prompts_type = prompts_type
|
| 32 |
|
| 33 |
+
|
| 34 |
+
class NurcSPDataset(GeneratorBasedBuilder):
|
| 35 |
BUILDER_CONFIGS = [
|
| 36 |
+
NurcSPConfig(name="original", description="Original audio prompts", prompts_type="original"),
|
| 37 |
+
NurcSPConfig(name="filtered", description="Filtered audio prompts", prompts_type="filtered"),
|
| 38 |
]
|
| 39 |
|
| 40 |
def _info(self):
|
| 41 |
+
return DatasetInfo(
|
| 42 |
+
features=datasets.Features(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
{
|
| 44 |
"audio_name": datasets.Value("string"),
|
| 45 |
"file_path": datasets.Value("string"),
|
|
|
|
| 59 |
"audio": datasets.Audio(sampling_rate=16_000),
|
| 60 |
}
|
| 61 |
)
|
| 62 |
+
)
|
| 63 |
|
| 64 |
def _split_generators(self, dl_manager):
|
| 65 |
+
prompts_urls = _PROMPTS_URLS # Default to original prompts URLs
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
if self.config.prompts_type == "filtered":
|
| 68 |
+
prompts_urls = _PROMPTS_FILTERED_URLS
|
| 69 |
+
|
| 70 |
+
prompts_path = dl_manager.download(prompts_urls)
|
| 71 |
+
archive = dl_manager.download(_ARCHIVES)
|
| 72 |
|
| 73 |
return [
|
| 74 |
SplitGenerator(
|
| 75 |
name=Split.VALIDATION,
|
| 76 |
gen_kwargs={
|
| 77 |
+
"prompts_path": prompts_path["dev"],
|
| 78 |
+
"path_to_clips": _PATH_TO_CLIPS["dev"],
|
| 79 |
+
"audio_files": dl_manager.iter_archive(archive["dev"]),
|
| 80 |
+
}
|
| 81 |
),
|
| 82 |
SplitGenerator(
|
| 83 |
name=Split.TRAIN,
|
| 84 |
gen_kwargs={
|
| 85 |
"prompts_path": prompts_path["train"],
|
| 86 |
+
"path_to_clips": _PATH_TO_CLIPS["train"],
|
| 87 |
+
"audio_files": dl_manager.iter_archive(archive["train"]),
|
| 88 |
+
}
|
| 89 |
),
|
| 90 |
]
|
| 91 |
|
|
|
|
|
|
|
|
|
|
| 92 |
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
|
|
|
| 93 |
examples = {}
|
| 94 |
with open(prompts_path, "r") as f:
|
| 95 |
csv_reader = csv.DictReader(f)
|
| 96 |
for row in csv_reader:
|
| 97 |
+
audio_name = row['audio_name']
|
| 98 |
+
file_path = row['file_path']
|
| 99 |
+
text = row['text']
|
| 100 |
+
start_time = row['start_time']
|
| 101 |
+
end_time = row['end_time']
|
| 102 |
+
duration = row['duration']
|
| 103 |
+
quality = row['quality']
|
| 104 |
+
speech_genre = row['speech_genre']
|
| 105 |
+
speech_style = row['speech_style']
|
| 106 |
+
variety = row['variety']
|
| 107 |
+
accent = row['accent']
|
| 108 |
+
sex = row['sex']
|
| 109 |
+
age_range = row['age_range']
|
| 110 |
+
num_speakers = row['num_speakers']
|
| 111 |
+
speaker_id = row['speaker_id']
|
| 112 |
+
examples[file_path] = {
|
| 113 |
+
"audio_name": audio_name,
|
| 114 |
+
"file_path": file_path,
|
| 115 |
+
"text": text,
|
| 116 |
+
"start_time": start_time,
|
| 117 |
+
"end_time": end_time,
|
| 118 |
+
"duration": duration,
|
| 119 |
+
"quality": quality,
|
| 120 |
+
"speech_genre": speech_genre,
|
| 121 |
+
"speech_style": speech_style,
|
| 122 |
+
"variety": variety,
|
| 123 |
+
"accent": accent,
|
| 124 |
+
"sex": sex,
|
| 125 |
+
"age_range": age_range,
|
| 126 |
+
"num_speakers": num_speakers,
|
| 127 |
+
"speaker_id": speaker_id,
|
| 128 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
inside_clips_dir = False
|
| 130 |
+
id_ = 0
|
| 131 |
for path, f in audio_files:
|
|
|
|
| 132 |
if path.startswith(path_to_clips):
|
| 133 |
inside_clips_dir = True
|
| 134 |
if path in examples:
|
|
|
|
|
|
|
| 135 |
audio = {"path": path, "bytes": f.read()}
|
| 136 |
yield id_, {**examples[path], "audio": audio}
|
| 137 |
id_ += 1
|
|
|
|
|
|
|
|
|
|
| 138 |
elif inside_clips_dir:
|
| 139 |
break
|
|
|
|
|
|
|
|
|
|
|
|