File size: 1,990 Bytes
6f00a7d
 
8f4a402
 
 
 
 
 
 
 
9a7be4b
8f4a402
 
 
 
6f00a7d
 
 
 
 
 
 
 
 
8f4a402
 
 
 
 
 
 
 
 
 
 
ad9d082
 
8f4a402
 
 
 
ad9d082
8f4a402
6f00a7d
 
ad9d082
 
8f4a402
6f00a7d
 
 
 
 
8f4a402
6f00a7d
ad9d082
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

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):
                # Join data_dir with utterance_path for the audio file
                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"]),
                }