Achitha commited on
Commit
278e4bb
·
1 Parent(s): 74f8781

Create simple_tamil.py

Browse files
Files changed (1) hide show
  1. simple_tamil.py +107 -0
simple_tamil.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
15
+ """IISc-MILE Tamil ASR Corpus contains transcribed speech corpus for training ASR systems for Tamil language. It contains ~150 hours of read speech data collected from 531 speakers in a noise-free recording environment with high quality USB microphones. """
16
+
17
+
18
+ import json
19
+ import os
20
+
21
+ import datasets
22
+
23
+ _METADATA_URLS = {
24
+ "train": "data/train.jsonl",
25
+ "test": "data/test.jsonl"
26
+ }
27
+ _URLS = {
28
+ "train": "data/train.tar.gz",
29
+ "test": "data/test.tar.gz",
30
+
31
+ }
32
+
33
+ class simple_data(datasets.GeneratorBasedBuilder):
34
+
35
+ VERSION = datasets.Version("1.1.0")
36
+ def _info(self):
37
+ features = datasets.Features(
38
+ {
39
+ "audio": datasets.Audio(sampling_rate=16_000),
40
+ "file_name": datasets.Value("string"),
41
+ "sentence": datasets.Value("string"),
42
+ }
43
+ )
44
+ return datasets.DatasetInfo(
45
+ description=_DESCRIPTION,
46
+ features=features,
47
+ supervised_keys=("sentence", "label"),
48
+ homepage=_HOMEPAGE,
49
+ license=_LICENSE,
50
+ citation=_CITATION,
51
+ )
52
+
53
+ def _split_generators(self, dl_manager):
54
+ metadata_paths = dl_manager.download(_METADATA_URLS)
55
+ train_archive = dl_manager.download(_URLS["train"])
56
+ test_archive = dl_manager.download(_URLS["test"])
57
+ local_extracted_train_archive = dl_manager.extract(train_archive) if not dl_manager.is_streaming else None
58
+ local_extracted_test_archive = dl_manager.extract(test_archive) if not dl_manager.is_streaming else None
59
+ test_archive = dl_manager.download(_URLS["test"])
60
+ train_dir = "train"
61
+ test_dir = "test"
62
+
63
+ return [
64
+ datasets.SplitGenerator(
65
+ name=datasets.Split.TRAIN,
66
+ gen_kwargs={
67
+ "metadata_path": metadata_paths["train"],
68
+ "local_extracted_archive": local_extracted_train_archive,
69
+ "path_to_clips": train_dir + "/mp3",
70
+ "audio_files": dl_manager.iter_archive(train_archive),
71
+ },
72
+ ),
73
+ datasets.SplitGenerator(
74
+ name=datasets.Split.TEST,
75
+ gen_kwargs={
76
+ "metadata_path": metadata_paths["test"],
77
+ "local_extracted_archive": local_extracted_test_archive,
78
+ "path_to_clips": test_dir + "/mp3",
79
+ "audio_files": dl_manager.iter_archive(test_archive),
80
+ },
81
+ ),
82
+
83
+ ]
84
+
85
+ def _generate_examples(self, metadata_path, local_extracted_archive, path_to_clips, audio_files):
86
+ """Yields examples as (key, example) tuples."""
87
+ examples = {}
88
+ with open(metadata_path, encoding="utf-8") as f:
89
+ for key, row in enumerate(f):
90
+ data = json.loads(row)
91
+ examples[data["file_name"]] = data
92
+ inside_clips_dir = False
93
+ id_ = 0
94
+ for path, f in audio_files:
95
+ if path.startswith(path_to_clips):
96
+ inside_clips_dir = True
97
+ if path in examples:
98
+ result = examples[path]
99
+ path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
100
+ result["audio"] = {"path": path, "bytes": f.read()}
101
+ result["file_name"] = path
102
+ yield id_, result
103
+ id_ += 1
104
+ elif inside_clips_dir:
105
+ break
106
+
107
+