File size: 2,027 Bytes
5ad0b6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import csv
import datasets
from datasets import Audio

_DESCRIPTION = "Cleaned Nepali ASR dataset with audio and transcriptions."
_CITATION = ""
_HOMEPAGE = ""

class NepaliASRConfig(datasets.BuilderConfig):
    def __init__(self, **kwargs):
        super(NepaliASRConfig, self).__init__(**kwargs)

class NepaliASRDataset(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [
        NepaliASRConfig(name="default", version=datasets.Version("1.0.0"), description="Nepali ASR Dataset")
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({
                "utterance_id": datasets.Value("string"),
                "speaker_id": datasets.Value("string"),
                "transcription": datasets.Value("string"),
                "audio": Audio(sampling_rate=16_000),
            }),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        archive_path = dl_manager.download_and_extract(self.config.data_dir)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "tsv_path": os.path.join(archive_path, "validation_transcriptions.tsv"),
                    "data_dir": archive_path,
                },
            )
        ]

    def _generate_examples(self, tsv_path, data_dir):
        with open(tsv_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"],
                    "transcription": row["transcription"],
                    "audio": audio_path,
                }