root commited on
Commit
f5266f5
1 Parent(s): cf670d9
Files changed (1) hide show
  1. gigaspeech2_metadata.py +0 -150
gigaspeech2_metadata.py DELETED
@@ -1,150 +0,0 @@
1
- import os
2
- from collections import OrderedDict
3
- from pathlib import Path
4
- import datasets
5
- import os
6
-
7
-
8
- class Gigaspeech2Config(datasets.BuilderConfig):
9
- """BuilderConfig for Yodas."""
10
-
11
- def __init__(self, lang, version, **kwargs):
12
- self.language = lang
13
- self.base_data_path = f"data/{lang}"
14
-
15
- description = (
16
- f"Youtube speech to text dataset in {self.language}."
17
- )
18
- super(Gigaspeech2Config, self).__init__(
19
- name=lang,
20
- version=datasets.Version(version),
21
- description=description,
22
- **kwargs,
23
- )
24
-
25
-
26
- DEFAULT_CONFIG_NAME = "all"
27
- LANGS = ['id', 'th', 'vi']
28
- VERSION = "1.0.1"
29
-
30
- class Gigaspeech2(datasets.GeneratorBasedBuilder):
31
- """Yodas dataset."""
32
-
33
- BUILDER_CONFIGS = [
34
- Gigaspeech2Config(lang, version=VERSION) for lang in LANGS
35
- ]
36
-
37
- VERSION = datasets.Version("1.0.1")
38
-
39
- def _info(self):
40
- return datasets.DatasetInfo(
41
- description="Gigaspeech2",
42
- features=datasets.Features(
43
- OrderedDict(
44
- [
45
- # ("id", datasets.Value("string")),
46
- # ("utt_id", datasets.Value("string")),
47
- ("audio", datasets.Audio(sampling_rate=16_000)),
48
- ("text", datasets.Value("string")),
49
- ]
50
- )
51
- ),
52
- supervised_keys=None,
53
- homepage="", # TODO
54
- citation="", # TODO
55
- )
56
-
57
- def _split_generators(self, dl_manager):
58
- """Returns SplitGenerators."""
59
- # TODO
60
-
61
- # total_cnt = lang2shard_cnt[self.config.name]
62
-
63
- # idx_lst = [f"{i:08d}" for i in range(total_cnt)]
64
- # idx_lst = ["0-0", "0-1"]
65
- # audio_tar_files = dl_manager.download([f"{self.config.base_data_path}/test.tar.gz"])
66
- audio_tar_files = dl_manager.download([f"{self.config.base_data_path}/test.tar.gz"])
67
- # text_files = dl_manager.download([f"{self.config.base_data_path}/text/{i:08d}.txt" for i in range(total_cnt)])
68
- #duration_files = dl_manager.download([f"{self.config.base_data_path}/duration/{i:08d}.txt" for i in range(total_cnt)])
69
-
70
- if dl_manager.is_streaming:
71
- audio_archives = [dl_manager.iter_archive(audio_tar_file) for audio_tar_file in audio_tar_files]
72
- # text_archives = [dl_manager.extract(text_file) for text_file in text_files]
73
-
74
- else:
75
- print("extracting audio ...")
76
- extracted_audio_archives = dl_manager.extract(audio_tar_files)
77
-
78
- audio_archives = []
79
- text_archives = []
80
- # audio_archives.append(str(extracted_dir)+'/'+idx)
81
- # for idx, audio_tar_file, extracted_dir, text_file in zip(idx_lst, audio_tar_files, extracted_audio_archives, text_files):
82
- # audio_archives.append(str(extracted_dir)+'/'+idx)
83
- # text_archives.append(text_file)
84
- for extracted_dir in extracted_audio_archives:
85
- audio_archives.append(str(extracted_dir)+'/'+"test")
86
-
87
-
88
- return [
89
- datasets.SplitGenerator(
90
- name=datasets.Split.TEST,
91
- gen_kwargs={
92
- "is_streaming": dl_manager.is_streaming,
93
- "audio_archives": audio_archives,
94
- # 'text_archives': text_archives,
95
- },
96
- ),
97
- ]
98
-
99
- def _generate_examples(self, is_streaming, audio_archives):
100
- """Yields examples."""
101
-
102
- id_ = 0
103
-
104
- text_archives = ["asdf" for _ in audio_archives]
105
- if is_streaming:
106
- # for tar_file, text_file in zip(audio_archives, text_archives):
107
- for tar_file in audio_archives:
108
- utt2text = {}
109
- for path, audio_f in tar_file:
110
- path = Path(path)
111
- utt_id = path.stem
112
-
113
-
114
- result = {
115
- 'id': id_,
116
- 'utt_id': utt_id,
117
- 'audio': {"path": None, "bytes": audio_f.read()},
118
- 'text': "asdf",
119
- }
120
-
121
- yield id_, result
122
- id_ += 1
123
- else:
124
- for extracted_dir, text_file in zip(audio_archives, text_archives):
125
-
126
- utt2text = {}
127
- extract_root_dir = Path(extracted_dir).parent
128
- extracted_dir = list(extract_root_dir.glob('./*'))[0]
129
-
130
- with open(text_file) as f:
131
- for _, row in enumerate(f):
132
- row = row.strip().split(maxsplit=1)
133
- utt2text[row[0]] = row[1]
134
-
135
- for audio_file in list(Path(extracted_dir).glob('*')):
136
-
137
- utt_id = audio_file.stem
138
- if utt_id in utt2text:
139
-
140
- result = {
141
- 'id': id_,
142
- 'utt_id': utt_id,
143
- 'audio': {"path": str(audio_file.absolute()), "bytes": open(audio_file, 'rb').read()},
144
- 'text': utt2text[utt_id]
145
- }
146
-
147
- yield id_, result
148
- id_ += 1
149
-
150
-