TenzinGayche commited on
Commit
b3917b0
1 Parent(s): 2784ec2

fixed loading script

Browse files
Files changed (1) hide show
  1. tibetan-voice.py +138 -0
tibetan-voice.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """TibetanVoice: The Stanford Question Answering Dataset."""
18
+
19
+
20
+ import csv
21
+ import os
22
+ import datasets
23
+ from datasets.tasks import QuestionAnsweringExtractive
24
+
25
+
26
+ logger = datasets.logging.get_logger(__name__)
27
+
28
+
29
+ _CITATION = """\
30
+ @article{2016arXiv160605250R,
31
+ author = {spsithar} and {TenzinGayche},
32
+ title = "TibetanVoice: 6.5 hours of validated transcribed speech data from 9 audio book in lhasa dialect ",
33
+ journal = {arXiv e-prints},
34
+ year = 2023,
35
+
36
+ }
37
+ """
38
+
39
+ _DESCRIPTION = """\
40
+ TibetanVoice: 6.5 hours of validated transcribed speech data from 9 audio book in lhasa dialect. The dataset is in tsv format with two columns, path and sentence. The path column contains the path to the audio file and the sentence column contains the corresponding sentence spoken in the audio file.
41
+
42
+
43
+ """
44
+
45
+
46
+ _URL = "https://huggingface.co/datasets/openpecha/tibetan_voice/resolve/main/transcripts%20/"
47
+ _DataUrl="https://huggingface.co/datasets/openpecha/tibetan_voice/resolve/main/audio/wav.tar"
48
+ _URLS = {
49
+ "train": _URL + "train-uni.tsv",
50
+ "valid": _URL + "valid-uni.tsv",
51
+ "test": _URL + "test-uni.tsv",
52
+ }
53
+
54
+
55
+ class TibetanVoiceConfig(datasets.BuilderConfig):
56
+ """BuilderConfig for TibetanVoice."""
57
+
58
+ def __init__(self, **kwargs):
59
+ """BuilderConfig for TibetanVoice.
60
+
61
+ Args:
62
+ **kwargs: keyword arguments forwarded to super.
63
+ """
64
+ super(TibetanVoiceConfig, self).__init__(**kwargs)
65
+
66
+
67
+ class TibetanVoice(datasets.GeneratorBasedBuilder):
68
+ """TibetanVoice: The Stanford Question Answering Dataset. Version 1.1."""
69
+
70
+ BUILDER_CONFIGS = [
71
+ TibetanVoiceConfig(
72
+ name="lhasa",
73
+ version=datasets.Version("1.0.0", ""),
74
+ description="The dataset comprises 6.5 hours of validated transcribed speech data from 9 audio book in lhasa dialect ",
75
+ ),
76
+ ]
77
+
78
+ def _info(self):
79
+ return datasets.DatasetInfo(
80
+ description=_DESCRIPTION,
81
+ features=datasets.Features(
82
+ {
83
+ "path": datasets.Value("string"),
84
+ "audio": datasets.features.Audio(sampling_rate=16_000),
85
+ "sentence": datasets.Value("string"),
86
+ }
87
+ ),
88
+ # No default supervised_keys (as we have to pass both question
89
+ # and context as input).
90
+ supervised_keys=None,
91
+ homepage="https://huggingface.co/datasets/TenzinGayche/Demo-datasets/",
92
+ citation=_CITATION,
93
+ )
94
+
95
+ def _split_generators(self, dl_manager):
96
+ downloaded_files = dl_manager.download_and_extract(_URLS)
97
+ downloaded_wav = dl_manager.download(_DataUrl)
98
+ wavs= dl_manager.iter_archive(downloaded_wav)
99
+ downloaded_wav = dl_manager.download_and_extract(_DataUrl)
100
+
101
+
102
+
103
+ return [
104
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"],"wavs":wavs,'wavfilepath':downloaded_wav}),
105
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"],"wavs":wavs,'wavfilepath':downloaded_wav}),
106
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"],"wavs":wavs,'wavfilepath':downloaded_wav}),
107
+ ]
108
+ def _generate_examples(self, filepath, wavs, wavfilepath):
109
+ """This function returns the examples in the raw (text) form."""
110
+ example_map = {}
111
+ logger.info("generating examples from = %s", filepath)
112
+ with open(filepath, encoding="utf-8") as f:
113
+ #tsv file
114
+ reader = csv.reader(f, delimiter="\t", quotechar=None)
115
+ for row in reader:
116
+ example_map[row["path"]] = row["sentence"]
117
+
118
+
119
+
120
+ audio_map = {}
121
+ for path, f in wavs:
122
+ _, filename = os.path.split(path)
123
+ audio_map[filename] = {"path": wavfilepath+'/'+path, "bytes": f.read()}
124
+
125
+ for key, path in enumerate(example_map.keys()):
126
+ _, filename = os.path.split(path)
127
+ sentence = example_map.get(filename, "")
128
+ audio = audio_map.get(filename, {})
129
+ example = {
130
+ "path": path,
131
+ "sentence": sentence,
132
+ "audio": audio
133
+ }
134
+ yield key, example
135
+
136
+
137
+
138
+