RaphaelOlivier
commited on
Commit
•
ef8f85a
1
Parent(s):
50a01e6
Upload librispeech_asr_adversarial.py
Browse files- librispeech_asr_adversarial.py +50 -32
librispeech_asr_adversarial.py
CHANGED
@@ -28,7 +28,8 @@ import datasets
|
|
28 |
_CITATION = """\
|
29 |
@inproceedings{panayotov2015librispeech,
|
30 |
title={Librispeech: an ASR corpus based on public domain audio books},
|
31 |
-
author={Panayotov, Vassil and Chen,
|
|
|
32 |
booktitle={Acoustics, Speech and Signal Processing (ICASSP), 2015 IEEE International Conference on},
|
33 |
pages={5206--5210},
|
34 |
year={2015},
|
@@ -54,7 +55,13 @@ dataset = dataset.map(map_to_array, remove_columns=["file"])
|
|
54 |
```
|
55 |
"""
|
56 |
# TODO: change
|
57 |
-
_DL_URL = "https://
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
|
60 |
class LibrispeechASRConfig(datasets.BuilderConfig):
|
@@ -97,43 +104,54 @@ class LibrispeechASR(datasets.GeneratorBasedBuilder):
|
|
97 |
)
|
98 |
|
99 |
def _split_generators(self, dl_manager):
|
|
|
100 |
archive_path = dl_manager.download_and_extract(
|
101 |
-
|
|
|
102 |
return [
|
103 |
-
datasets.SplitGenerator(name=
|
104 |
-
"archive_path": archive_path, "split_name": f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
]
|
106 |
|
107 |
def _generate_examples(self, archive_path, split_name):
|
108 |
"""Generate examples from a Librispeech archive_path."""
|
109 |
-
|
110 |
-
if split_name.endswith("
|
111 |
-
split_folder = split_name[
|
112 |
use_adv_transcript = True
|
113 |
else:
|
114 |
-
assert split_name.endswith("
|
115 |
-
split_folder = split_name[
|
116 |
use_adv_transcript = False
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
"file": os.path.join(audio_path, audio_file),
|
136 |
-
"audio": os.path.join(audio_path, audio_file),
|
137 |
-
"text": transcript,
|
138 |
-
}
|
139 |
-
yield split_key, example
|
|
|
28 |
_CITATION = """\
|
29 |
@inproceedings{panayotov2015librispeech,
|
30 |
title={Librispeech: an ASR corpus based on public domain audio books},
|
31 |
+
author={Panayotov, Vassil and Chen,
|
32 |
+
Guoguo and Povey, Daniel and Khudanpur, Sanjeev},
|
33 |
booktitle={Acoustics, Speech and Signal Processing (ICASSP), 2015 IEEE International Conference on},
|
34 |
pages={5206--5210},
|
35 |
year={2015},
|
|
|
55 |
```
|
56 |
"""
|
57 |
# TODO: change
|
58 |
+
_DL_URL = "https://data.mendeley.com/api/datasets/kbdt923ybx/draft/files/65e7d2bf-16f7-4eed-8ac3-e3ae5d67aa40?a=7e4a4a33-35dd-4608-9d3a-24c0de170260"
|
59 |
+
|
60 |
+
_DL_URLS = {
|
61 |
+
"adv": {
|
62 |
+
"test": _DL_URL,
|
63 |
+
}
|
64 |
+
}
|
65 |
|
66 |
|
67 |
class LibrispeechASRConfig(datasets.BuilderConfig):
|
|
|
104 |
)
|
105 |
|
106 |
def _split_generators(self, dl_manager):
|
107 |
+
|
108 |
archive_path = dl_manager.download_and_extract(
|
109 |
+
_DL_URLS[self.config.name])
|
110 |
+
|
111 |
return [
|
112 |
+
datasets.SplitGenerator(name="natural_nat_txt", gen_kwargs={
|
113 |
+
"archive_path": archive_path["test"], "split_name": f"natural_nat_txt"}),
|
114 |
+
datasets.SplitGenerator(name="adv_0.04_nat_txt", gen_kwargs={
|
115 |
+
"archive_path": archive_path["test"], "split_name": f"adv_0.04_nat_txt"}),
|
116 |
+
datasets.SplitGenerator(name="adv_0.015_nat_txt", gen_kwargs={
|
117 |
+
"archive_path": archive_path["test"], "split_name": f"adv_0.015_nat_txt"}),
|
118 |
+
datasets.SplitGenerator(name="adv_0.015_RIR_nat_txt", gen_kwargs={
|
119 |
+
"archive_path": archive_path["test"], "split_name": f"adv_0.015_RIR_nat_txt"}),
|
120 |
+
datasets.SplitGenerator(name="natural_adv_txt", gen_kwargs={
|
121 |
+
"archive_path": archive_path["test"], "split_name": f"natural_adv_txt"}),
|
122 |
+
datasets.SplitGenerator(name="adv_0.04_adv_txt", gen_kwargs={
|
123 |
+
"archive_path": archive_path["test"], "split_name": f"adv_0.04_adv_txt"}),
|
124 |
+
datasets.SplitGenerator(name="adv_0.015_adv_txt", gen_kwargs={
|
125 |
+
"archive_path": archive_path["test"], "split_name": f"adv_0.015_adv_txt"}),
|
126 |
+
datasets.SplitGenerator(name="adv_0.015_RIR_adv_txt", gen_kwargs={
|
127 |
+
"archive_path": archive_path["test"], "split_name": f"adv_0.015_RIR_adv_txt"}),
|
128 |
]
|
129 |
|
130 |
def _generate_examples(self, archive_path, split_name):
|
131 |
"""Generate examples from a Librispeech archive_path."""
|
132 |
+
transcript_file = os.path.join(archive_path, "manifest.txt")
|
133 |
+
if split_name.endswith("_adv_txt"):
|
134 |
+
split_folder = split_name[: -8]
|
135 |
use_adv_transcript = True
|
136 |
else:
|
137 |
+
assert split_name.endswith("_nat_txt")
|
138 |
+
split_folder = split_name[: -8]
|
139 |
use_adv_transcript = False
|
140 |
|
141 |
+
path = os.path.dirname(transcript_file)
|
142 |
+
audio_path = os.path.join(path, split_folder)
|
143 |
+
with open(transcript_file) as f:
|
144 |
+
for line in f:
|
145 |
+
line = line.strip()
|
146 |
+
key, og_transcript, adv_transcript = line.split(",", 2)
|
147 |
+
transcript = adv_transcript if use_adv_transcript else og_transcript
|
148 |
+
suffix = "nat" if split_folder == "natural" else "adv"
|
149 |
+
audio_file = f"{key}_{suffix}.wav"
|
150 |
+
split_key = key+"_"+suffix+"_"+split_name
|
151 |
+
example = {
|
152 |
+
"id": split_key,
|
153 |
+
"file": os.path.join(audio_path, audio_file),
|
154 |
+
"audio": os.path.join(audio_path, audio_file),
|
155 |
+
"text": transcript,
|
156 |
+
}
|
157 |
+
yield split_key, example
|
|
|
|
|
|
|
|
|
|