import csv import datasets _PROMPTS_URLS = { "train": "train.csv", "validation": "validation.csv", "test": "test.csv", } _ARCHIVES = { "train": "train.tar.gz", "validation": "validation.tar.gz", "test": "test.tar.gz", } _PATH_TO_CLIPS = { "train": "train", "validation": "validation", "test": "test", } class MUPEASRDataset(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( features=datasets.Features( { "audio_id": datasets.Value("int64"), "audio_name": datasets.Value("string"), "file_path": datasets.Value("string"), "speaker_type": datasets.Value("string"), "speaker_code": datasets.Value("string"), "speaker_gender": datasets.Value("string"), "education": datasets.Value("string"), "birth_state": datasets.Value("string"), "birth_country": datasets.Value("string"), "age": datasets.Value("int64"), "recording_year": datasets.Value("int64"), "audio_quality": datasets.Value("string"), "start_time": datasets.Value("float32"), "end_time": datasets.Value("float32"), "duration": datasets.Value("float32"), "normalized_text": datasets.Value("string"), "original_text": datasets.Value("string"), "audio": datasets.Audio(sampling_rate=16_000), } ) ) def _split_generators(self, dl_manager): prompts_path = dl_manager.download(_PROMPTS_URLS) archive = dl_manager.download(_ARCHIVES) return [ datasets.SplitGenerator( name = datasets.Split.VALIDATION, gen_kwargs = { "prompts_path": prompts_path["validation"], "path_to_clips": _PATH_TO_CLIPS["validation"], "audio_files": dl_manager.iter_archive(archive["validation"]), } ), datasets.SplitGenerator( name = datasets.Split.TEST, gen_kwargs = { "prompts_path": prompts_path["test"], "path_to_clips": _PATH_TO_CLIPS["test"], "audio_files": dl_manager.iter_archive(archive["test"]), } ), datasets.SplitGenerator( name = datasets.Split.TRAIN, gen_kwargs = { "prompts_path": prompts_path["train"], "path_to_clips": _PATH_TO_CLIPS["train"], "audio_files": dl_manager.iter_archive(archive["train"]), } ), ] 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: audio_id = row['audio_id'] audio_name = row['audio_name'] file_path = row['file_path'] speaker_type = row['speaker_type'] speaker_code = row['speaker_code'] speaker_gender = row['speaker_gender'] education = row['education'] birth_state = row['birth_state'] birth_country = row['birth_country'] age = row['age'] recording_year = row['recording_year'] audio_quality = row['audio_quality'] start_time = row['start_time'] end_time = row['end_time'] duration = row['duration'] normalized_text = row['normalized_text'] original_text = row['original_text'] examples[file_path] = { "audio_id" : audio_id, "audio_name" : audio_name, "file_path" : file_path, "speaker_type" : speaker_type, "speaker_code" : speaker_code, "speaker_gender" : speaker_gender, "education" : education, "birth_state" : birth_state, "birth_country" : birth_country, "age" : age, "recording_year" : recording_year, "audio_quality" : audio_quality, "start_time" : start_time, "end_time" : end_time, "duration" : duration, "normalized_text" : normalized_text, "original_text" : original_text, } inside_clips_dir = False id_ = 0 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