|
import os |
|
import csv |
|
import datasets |
|
|
|
class NepaliASRConfig(datasets.BuilderConfig): |
|
def __init__(self, **kwargs): |
|
super().__init__(**kwargs) |
|
|
|
class NepaliASR(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
NepaliASRConfig(version=datasets.Version("1.0.0"), description="validation_nepali_asr"), |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
features=datasets.Features( |
|
{ |
|
"utterance_id": datasets.Value("string"), |
|
"speaker_id": datasets.Value("string"), |
|
"audio": datasets.Audio(sampling_rate=16000), |
|
"transcription": datasets.Value("string"), |
|
"num_frames": datasets.Value("int32"), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage="", |
|
license="", |
|
citation="", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"transcriptions_path": os.path.join("validation_dataset", "validation_transcriptions.tsv"), |
|
"data_dir": "validation_dataset", |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, transcriptions_path, data_dir): |
|
with open(transcriptions_path, encoding="utf-8") as f: |
|
reader = csv.DictReader(f, delimiter="\t") |
|
for idx, row in enumerate(reader): |
|
|
|
audio_path = os.path.join(data_dir, row["utterance_path"]) |
|
yield idx, { |
|
"utterance_id": row["utterance_id"], |
|
"speaker_id": row["speaker_id"], |
|
"audio": audio_path, |
|
"transcription": row["transcription"], |
|
"num_frames": int(row["num_frames"]), |
|
} |
|
|
|
|
|
|