import os import datasets class AudioTextgridDataset(datasets.GeneratorBasedBuilder): def _info(self): return datasets.DatasetInfo( features=datasets.Features({ "audio": datasets.Audio(), "textgrid": datasets.Value("string"), }) ) def _split_generators(self, dl_manager): data_dir = dl_manager.download_and_extract("path/to/dataset_folder") return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"data_dir": data_dir}, ), ] def _generate_examples(self, data_dir): metadata_path = os.path.join(data_dir, "metadata.csv") with open(metadata_path, "r") as f: for id, line in enumerate(f): audio_file, textgrid_file = line.strip().split(",") yield id, { "audio": os.path.join(data_dir, "data", audio_file), "textgrid": open(os.path.join(data_dir, "data", textgrid_file)).read(), }