|
import csv
|
|
import datasets
|
|
from datasets import BuilderConfig, GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split
|
|
|
|
_PROSODIC_PROMPTS_URLS = {
|
|
"validation": "prosodic/audios_dev_metadata.csv",
|
|
"train": "prosodic/audios_train_metadata.csv",
|
|
}
|
|
|
|
_AUTOMATIC_PROMPTS_URLS = {
|
|
"validation": "automatic/audios_dev_metadata.csv",
|
|
"train": "automatic/audios_train_metadata.csv",
|
|
}
|
|
|
|
_ARCHIVES = {
|
|
"validation_prosodic": "prosodic/audios_dev.zip",
|
|
"train_prosodic": "prosodic/audios_train.zip",
|
|
"validation_automatic": "automatic/audios_dev.zip",
|
|
"train_automatic": "automatic/audios_train.zip",
|
|
}
|
|
|
|
_PATH_TO_CLIPS = {
|
|
"validation_prosodic": "prosodic/audios_dev",
|
|
"train_prosodic": "prosodic/audios_train",
|
|
"validation_automatic": "automatic/audios_dev",
|
|
"train_automatic": "automatic/audios_train",
|
|
}
|
|
|
|
class EntoaConfig(BuilderConfig):
|
|
def __init__(self, prompts_type="prosodic", **kwargs):
|
|
super().__init__(**kwargs)
|
|
self.prompts_type = prompts_type
|
|
|
|
class EntoaDataset(GeneratorBasedBuilder):
|
|
BUILDER_CONFIGS = [
|
|
EntoaConfig(name="prosodic", description="Prosodic audio prompts", prompts_type="prosodic"),
|
|
EntoaConfig(name="automatic", description="Automatic audio prompts", prompts_type="automatic"),
|
|
]
|
|
|
|
def _info(self):
|
|
if self.config.name == "prosodic":
|
|
features = datasets.Features(
|
|
{
|
|
"path": datasets.Value("string"),
|
|
"name": datasets.Value("string"),
|
|
"speaker": datasets.Value("string"),
|
|
"start_time": datasets.Value("string"),
|
|
"end_time": datasets.Value("string"),
|
|
"normalized_text": datasets.Value("string"),
|
|
"text": datasets.Value("string"),
|
|
"duration": datasets.Value("string"),
|
|
"type": datasets.Value("string"),
|
|
"year": datasets.Value("string"),
|
|
"gender": datasets.Value("string"),
|
|
"age_range": datasets.Value("string"),
|
|
"total_duration": datasets.Value("string"),
|
|
"quality": datasets.Value("string"),
|
|
"theme": datasets.Value("string"),
|
|
"audio": datasets.Audio(sampling_rate=16_000),
|
|
}
|
|
)
|
|
else:
|
|
features = datasets.Features(
|
|
{
|
|
"audio_name": datasets.Value("string"),
|
|
"file_path": datasets.Value("string"),
|
|
"text": datasets.Value("string"),
|
|
"start_time": datasets.Value("string"),
|
|
"end_time": datasets.Value("string"),
|
|
"duration": datasets.Value("string"),
|
|
"quality": datasets.Value("string"),
|
|
"speech_genre": datasets.Value("string"),
|
|
"speech_style": datasets.Value("string"),
|
|
"variety": datasets.Value("string"),
|
|
"accent": datasets.Value("string"),
|
|
"sex": datasets.Value("string"),
|
|
"age_range": datasets.Value("string"),
|
|
"num_speakers": datasets.Value("string"),
|
|
"speaker_id": datasets.Value("string"),
|
|
"audio": datasets.Audio(sampling_rate=16_000),
|
|
}
|
|
)
|
|
return DatasetInfo(features=features)
|
|
|
|
def _split_generators(self, dl_manager):
|
|
prompts_urls = _PROSODIC_PROMPTS_URLS if self.config.name == "prosodic" else _AUTOMATIC_PROMPTS_URLS
|
|
path_to_clips = _PATH_TO_CLIPS
|
|
archive = dl_manager.download(_ARCHIVES)
|
|
prompts_path = dl_manager.download(prompts_urls)
|
|
|
|
return [
|
|
SplitGenerator(
|
|
name=Split.VALIDATION,
|
|
gen_kwargs={
|
|
"prompts_path": prompts_path["validation"],
|
|
"path_to_clips": path_to_clips[f"validation_{self.config.name}"],
|
|
"audio_files": dl_manager.iter_archive(archive[f"validation_{self.config.name}"]),
|
|
},
|
|
),
|
|
SplitGenerator(
|
|
name=Split.TRAIN,
|
|
gen_kwargs={
|
|
"prompts_path": prompts_path["train"],
|
|
"path_to_clips": path_to_clips[f"train_{self.config.name}"],
|
|
"audio_files": dl_manager.iter_archive(archive[f"train_{self.config.name}"]),
|
|
},
|
|
),
|
|
]
|
|
|
|
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
|
examples = {}
|
|
with open(prompts_path, "r") as f:
|
|
csv_reader = csv.DictReader(f)
|
|
for row in csv_reader:
|
|
if self.config.name == "prosodic":
|
|
examples[row['path']] = {
|
|
"path": row['path'],
|
|
"name": row['name'],
|
|
"speaker": row['speaker'],
|
|
"start_time": row['start_time'],
|
|
"end_time": row['end_time'],
|
|
"normalized_text": row['normalized_text'],
|
|
"text": row['text'],
|
|
"duration": row['duration'],
|
|
"type": row['type'],
|
|
"year": row['year'],
|
|
"gender": row['gender'],
|
|
"age_range": row['age_range'],
|
|
"total_duration": row['total_duration'],
|
|
"quality": row['quality'],
|
|
"theme": row['theme'],
|
|
}
|
|
else:
|
|
examples[row['file_path']] = {
|
|
"audio_name": row['audio_name'],
|
|
"file_path": row['file_path'],
|
|
"text": row['text'],
|
|
"start_time": row['start_time'],
|
|
"end_time": row['end_time'],
|
|
"duration": row['duration'],
|
|
"quality": row['quality'],
|
|
"speech_genre": row['speech_genre'],
|
|
"speech_style": row['speech_style'],
|
|
"variety": row['variety'],
|
|
"accent": row['accent'],
|
|
"sex": row['sex'],
|
|
"age_range": row['age_range'],
|
|
"num_speakers": row['num_speakers'],
|
|
"speaker_id": row['speaker_id'],
|
|
}
|
|
|
|
id_ = 0
|
|
inside_clips_dir = False
|
|
for path, f in audio_files:
|
|
if path.startswith(path_to_clips):
|
|
inside_clips_dir = True
|
|
if path in examples:
|
|
audio = {"path": path, "bytes": f.read()}
|
|
yield id_, {**examples[path], "audio": audio}
|
|
id_ += 1
|
|
elif inside_clips_dir:
|
|
break
|
|
|