from collections import defaultdict import os import json import csv import datasets _NAME="raddromur_asr" _VERSION="1.0.0" _AUDIO_EXTENSIONS=".flac" _DESCRIPTION = """ The Raddrómur Corpus is intended for the speech recognition field and it is made out of radio podcasts mostly taken from RÚV (ruv.is). Such podcasts were selected because they contained a text script that matches with certain fidelity what is said during the show. After automatic segmentation of the episodes, the transcriptions were inferred using the scripts along with a forced alignment technique. """ _CITATION = """ @misc{carlosmenaraddromur2022, title={Raddrómur Icelandic Speech 22.09}, author={Hernández Mena, Carlos Daniel and Hedström, Staffan and Þórhallsdóttir, Ragnheiður and Fong, Judy Y. and Gunnarsson, Þorsteinn Daði and Sigurðardóttir, Helga Svala and Þorsteinsdóttir, Helga Lára and Guðnason, Jón}, year={2022}, url={http://hdl.handle.net/20.500.12537/286}, } """ _HOMEPAGE = "http://hdl.handle.net/20.500.12537/286" _LICENSE = "CC-BY-4.0, See https://creativecommons.org/licenses/by/4.0/" _BASE_DATA_DIR = "corpus/" _METADATA_TRAIN = os.path.join(_BASE_DATA_DIR,"files","metadata_train.tsv") _TARS_TRAIN = os.path.join(_BASE_DATA_DIR,"files","tars_train.paths") class RaddromurAsrConfig(datasets.BuilderConfig): """BuilderConfig for Raddrómur Corpus""" def __init__(self, name, **kwargs): name=_NAME super().__init__(name=name, **kwargs) class RaddromurAsr(datasets.GeneratorBasedBuilder): """Raddrómur Icelandic Speech 22.09""" VERSION = datasets.Version(_VERSION) BUILDER_CONFIGS = [ RaddromurAsrConfig( name=_NAME, version=datasets.Version(_VERSION), ) ] def _info(self): features = datasets.Features( { "audio_id": datasets.Value("string"), "audio": datasets.Audio(sampling_rate=16000), "podcast_id": datasets.Value("string"), "segment_num": datasets.Value("int32"), "start_time": datasets.Value("string"), "duration": datasets.Value("float32"), "mafia_score": datasets.Value("float32"), "normalized_text": datasets.Value("string"), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): metadata_train=dl_manager.download_and_extract(_METADATA_TRAIN) tars_train=dl_manager.download_and_extract(_TARS_TRAIN) hash_tar_files=defaultdict(dict) with open(tars_train,'r') as f: hash_tar_files['train']=[path.replace('\n','') for path in f] hash_meta_paths={"train":metadata_train} audio_paths = dl_manager.download(hash_tar_files) splits=["train"] local_extracted_audio_paths = ( dl_manager.extract(audio_paths) if not dl_manager.is_streaming else { split:[None] * len(audio_paths[split]) for split in splits } ) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "audio_archives":[dl_manager.iter_archive(archive) for archive in audio_paths["train"]], "local_extracted_archives_paths": local_extracted_audio_paths["train"], "metadata_paths": hash_meta_paths["train"], } ), ] def _generate_examples(self, audio_archives, local_extracted_archives_paths, metadata_paths): features = ["podcast_id","segment_num","start_time","duration","mafia_score","normalized_text"] with open(metadata_paths) as f: metadata = {x["audio_id"]: x for x in csv.DictReader(f, delimiter="\t")} for audio_archive, local_extracted_archive_path in zip(audio_archives, local_extracted_archives_paths): for audio_filename, audio_file in audio_archive: audio_id = audio_filename.split(os.sep)[-1].split(_AUDIO_EXTENSIONS)[0] path = os.path.join(local_extracted_archive_path, audio_filename) if local_extracted_archive_path else audio_filename yield audio_id, { "audio_id": audio_id, **{feature: metadata[audio_id][feature] for feature in features}, "audio": {"path": path, "bytes": audio_file.read()}, }