SumitMdhr commited on
Commit
43d336c
·
verified ·
1 Parent(s): a581298

Upload builder.py

Browse files
Files changed (1) hide show
  1. builder.py +137 -0
builder.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Leading and Trailing Silences Removed Large Nepali ASR Dataset"""
15
+
16
+ import os
17
+ import csv
18
+
19
+ import datasets
20
+
21
+
22
+ _CITATION = """\
23
+ @inproceedings{kjartansson-etal-sltu2018,
24
+ title = {{Crowd-Sourced Speech Corpora for Javanese, Sundanese, Sinhala, Nepali, and Bangladeshi Bengali}},
25
+ author = {Oddur Kjartansson and Supheakmungkol Sarin and Knot Pipatsrisawat and Martin Jansche and Linne Ha},
26
+ booktitle = {Proc. The 6th Intl. Workshop on Spoken Language Technologies for Under-Resourced Languages (SLTU)},
27
+ year = {2018},
28
+ address = {Gurugram, India},
29
+ month = aug,
30
+ pages = {52--55},
31
+ URL = {http://dx.doi.org/10.21437/SLTU.2018-11}
32
+ }
33
+ """
34
+
35
+ _DESCRIPTION = """\
36
+ This data set contains transcribed audio data for Nepali. The data set consists of flac files, and a TSV file. The file utt_spk_text.tsv contains a FileID, anonymized UserID and the transcription of audio in the file.
37
+ The data set has been manually quality checked, but there might still be errors.
38
+ The audio files are sampled at rate of 16KHz, and leading and trailing silences are trimmed using torchaudio's voice activity detection.
39
+ """
40
+
41
+ # Official homepage for the dataset
42
+ _HOMEPAGE = "https://www.openslr.org/54/"
43
+
44
+ # The licence for the dataset
45
+ _LICENSE = "license:cc-by-sa-4.0"
46
+
47
+ # TODO: Add link to the official dataset URLs here
48
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
49
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
50
+
51
+
52
+ # _URLS = {
53
+ # 'cleaned': {
54
+ # "index_file": "https://huggingface.co/datasets/spktsagar/openslr-nepali-asr-cleaned/resolve/main/data/utt_spk_text_clean.tsv",
55
+ # "zipfiles": [
56
+ # f"https://huggingface.co/datasets/spktsagar/openslr-nepali-asr-cleaned/resolve/main/data/asr_nepali_{k}.zip"
57
+ # for k in [*range(10), *'abcdef']
58
+ # ],
59
+ # },
60
+ # 'original': {
61
+ # "index_file": "https://huggingface.co/datasets/spktsagar/openslr-nepali-asr-cleaned/resolve/main/data/utt_spk_text_orig.tsv",
62
+ # "zipfiles": [
63
+ # f"https://www.openslr.org/resources/54/asr_nepali_{k}.zip"
64
+ # for k in [*range(10), *'abcdef']
65
+ # ],
66
+ # },
67
+ # }
68
+ _URL = "https://huggingface.co/datasets/SumitMdhr/ASR/resolve/main/"
69
+ _URLS = {
70
+ "zipfile": _URL + "CLEAN_DATA.zip",
71
+ "index_file": _URL + "metadata1.tsv",
72
+ }
73
+
74
+
75
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
76
+ class NepaliAsr(datasets.GeneratorBasedBuilder):
77
+ """End Silences Removed Large Nepali ASR Dataset"""
78
+
79
+ VERSION = datasets.Version("1.0.0")
80
+
81
+ def _info(self):
82
+ features = datasets.Features(
83
+ {
84
+ "utterance_id": datasets.Value("string"),
85
+ "utterance": datasets.Audio(sampling_rate=16000),
86
+ "transcription": datasets.Value("string"),
87
+ }
88
+ )
89
+ return datasets.DatasetInfo(
90
+ description=_DESCRIPTION,
91
+ # Here we define them above because they are different between the two configurations
92
+ features=features,
93
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
94
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
95
+ # supervised_keys=("sentence", "label"),
96
+ # Homepage of the dataset for documentation
97
+ homepage=_HOMEPAGE,
98
+ # License for the dataset if available
99
+ license=_LICENSE,
100
+ # Citation for the dataset
101
+ citation=_CITATION,
102
+ task_templates=[
103
+ datasets.tasks.AutomaticSpeechRecognition(
104
+ audio_column="utterance", transcription_column="transcription"
105
+ )
106
+ ],
107
+ )
108
+
109
+ def _split_generators(self, dl_manager):
110
+ index_file = dl_manager.download(_URLS["index_file"])
111
+ zip_paths = _URLS["zipfile"]
112
+ audio_paths = dict(
113
+ zip([url[-5] for url in _URLS["zipfile"]], dl_manager.extract(zip_paths))
114
+ )
115
+ for path in zip_paths:
116
+ if os.path.exists(path):
117
+ os.remove(path)
118
+ return [
119
+ datasets.SplitGenerator(
120
+ name=datasets.Split.TRAIN,
121
+ gen_kwargs={
122
+ "index_file": index_file,
123
+ "audio_paths": audio_paths,
124
+ },
125
+ ),
126
+ ]
127
+
128
+ def _generate_examples(self, index_file, audio_paths):
129
+ with open(index_file, encoding="utf-8") as f:
130
+ reader = csv.DictReader(f, delimiter="\t")
131
+ for key, row in enumerate(reader):
132
+ path = os.path.join(audio_paths, "CLEAN_DATA", f"{row['utterance_id']}")
133
+ yield key, {
134
+ "utterance_id": row["utterance_id"],
135
+ "utterance": path,
136
+ "transcription": row["transcription"],
137
+ }