import os import datasets import pandas as pd _DESCRIPTION = """\ This dataset is collected from Commonvoice for testing purposes. """ _CITATION = "Some citation" _data_dir = "data" class ASRTesting(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "path": datasets.Value("string"), "audio": datasets.Audio(sampling_rate=16_000), "transcript": datasets.Value("string"), } ), supervised_keys=None, citation=_CITATION, ) def _split_generators(self, dl_manager): download_dir = dl_manager.download_and_extract( { "files": os.path.join(_data_dir, "files.zip"), "metadata": os.path.join(_data_dir, "metadata.zip") } ) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "split": datasets.Split.TRAIN, "data_dir": os.path.join(download_dir["files"], "files"), "metapath": os.path.join(download_dir["metadata"], "metadata", "dataset.tsv"), }, ) ] def _generate_examples(self, data_dir, metapath, split): metadata = pd.read_csv(metapath, sep="\t") for key, row in metadata.iterrows(): audio_path = os.path.join(data_dir, row["audio"]) yield key, { "audio": audio_path, "transcript": row["transcript"], "path": audio_path, }