SumitMdhr commited on
Commit
3f8c170
·
verified ·
1 Parent(s): 71578a0

Upload builder.py

Browse files
Files changed (1) hide show
  1. builder.py +118 -0
builder.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # TODO: Add link to the official dataset URLs here
42
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
43
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
44
+
45
+
46
+ # _URLS = {
47
+ # 'cleaned': {
48
+ # "index_file": "https://huggingface.co/datasets/spktsagar/openslr-nepali-asr-cleaned/resolve/main/data/utt_spk_text_clean.tsv",
49
+ # "zipfiles": [
50
+ # f"https://huggingface.co/datasets/spktsagar/openslr-nepali-asr-cleaned/resolve/main/data/asr_nepali_{k}.zip"
51
+ # for k in [*range(10), *'abcdef']
52
+ # ],
53
+ # },
54
+ # 'original': {
55
+ # "index_file": "https://huggingface.co/datasets/spktsagar/openslr-nepali-asr-cleaned/resolve/main/data/utt_spk_text_orig.tsv",
56
+ # "zipfiles": [
57
+ # f"https://www.openslr.org/resources/54/asr_nepali_{k}.zip"
58
+ # for k in [*range(10), *'abcdef']
59
+ # ],
60
+ # },
61
+ # }
62
+ _URL = "https://huggingface.co/datasets/SumitMdhr/ASR/resolve/main/"
63
+ _URLS = {
64
+ "zipfile": _URL + "CLEAN_DATA.zip",
65
+ "index_file": _URL + "metedata1.tsv",
66
+ }
67
+
68
+
69
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
70
+ class NepaliAsr(datasets.GeneratorBasedBuilder):
71
+ """End Silences Removed Large Nepali ASR Dataset"""
72
+
73
+ VERSION = datasets.Version("1.0.0")
74
+
75
+ def _info(self):
76
+ return datasets.DatasetInfo(
77
+ description=_DESCRIPTION,
78
+ features=datasets.Features(
79
+ {
80
+ "utterance_id": datasets.Value("string"),
81
+ "transcription": datasets.Value("string"),
82
+ "utterance": datasets.Audio(),
83
+ }
84
+ ),
85
+ homepage="https://www.openslr.org/54/",
86
+ # Citation for the dataset
87
+ citation=_CITATION,
88
+ task_templates=[
89
+ datasets.tasks.AutomaticSpeechRecognition(
90
+ audio_column="utterance", transcription_column="transcription"
91
+ )
92
+ ],
93
+ )
94
+
95
+ def _split_generators(self, dl_manager):
96
+ index_file = dl_manager.download(_URLS["index_file"])
97
+ zip_paths = dl_manager.download(_URLS["zipfile"])
98
+ audio_paths = dl_manager.extract(zip_paths)
99
+ return [
100
+ datasets.SplitGenerator(
101
+ name=datasets.Split.TRAIN,
102
+ gen_kwargs={
103
+ "index_file": index_file,
104
+ "audio_paths": audio_paths,
105
+ },
106
+ ),
107
+ ]
108
+
109
+ def _generate_examples(self, index_file, audio_paths):
110
+ with open(index_file, encoding="utf-8") as f:
111
+ reader = csv.DictReader(f, delimiter="\t")
112
+ for key, row in enumerate(reader):
113
+ path = os.path.join(audio_paths, "CLEAN_DATA", row["utterance_id"])
114
+ yield key, {
115
+ "utterance_id": row["utterance_id"],
116
+ "utterance": path,
117
+ "transcription": row["transcription"],
118
+ }