Datasets:
repatch
Browse files- vox_celeb.py +53 -48
vox_celeb.py
CHANGED
@@ -18,6 +18,7 @@
|
|
18 |
|
19 |
import json
|
20 |
import os
|
|
|
21 |
from getpass import getpass
|
22 |
from hashlib import sha256
|
23 |
from itertools import repeat
|
@@ -59,46 +60,47 @@ VoxCeleb is an audio-visual dataset consisting of short clips of human speech, e
|
|
59 |
"""
|
60 |
|
61 |
_URL = "https://mm.kaist.ac.kr/datasets/voxceleb"
|
|
|
62 |
|
63 |
_URLS = {
|
64 |
"video": {
|
65 |
-
"placeholder": "
|
66 |
"dev": (
|
67 |
-
"
|
68 |
-
"
|
69 |
-
"
|
70 |
-
"
|
71 |
-
"
|
72 |
-
"
|
73 |
-
"
|
74 |
-
"
|
75 |
-
"
|
76 |
),
|
77 |
-
"test": "
|
78 |
},
|
79 |
"audio1": {
|
80 |
-
"placeholder": "
|
81 |
"dev": (
|
82 |
-
"
|
83 |
-
"
|
84 |
-
"
|
85 |
-
"
|
86 |
),
|
87 |
-
"test": "
|
88 |
},
|
89 |
"audio2": {
|
90 |
-
"placeholder": "
|
91 |
"dev": (
|
92 |
-
"
|
93 |
-
"
|
94 |
-
"
|
95 |
-
"
|
96 |
-
"
|
97 |
-
"
|
98 |
-
"
|
99 |
-
"
|
100 |
),
|
101 |
-
"test": "
|
102 |
},
|
103 |
}
|
104 |
|
@@ -114,8 +116,7 @@ _PLACEHOLDER_MAPS = dict(
|
|
114 |
def _mp_download(
|
115 |
url,
|
116 |
tmp_path,
|
117 |
-
|
118 |
-
cred_pass,
|
119 |
resume_pos,
|
120 |
length,
|
121 |
queue,
|
@@ -127,7 +128,7 @@ def _mp_download(
|
|
127 |
if resume_pos != 0:
|
128 |
headers["Range"] = f"bytes={resume_pos}-"
|
129 |
response = requests.get(
|
130 |
-
url
|
131 |
)
|
132 |
if response.status_code >= 200 and response.status_code < 300:
|
133 |
for chunk in response.iter_content(chunk_size=65536):
|
@@ -140,7 +141,7 @@ def _mp_download(
|
|
140 |
class VoxCeleb(datasets.GeneratorBasedBuilder):
|
141 |
"""VoxCeleb is an unlabled dataset consisting of short clips of human speech from interviews on YouTube"""
|
142 |
|
143 |
-
VERSION = datasets.Version("1.
|
144 |
|
145 |
BUILDER_CONFIGS = [
|
146 |
datasets.BuilderConfig(
|
@@ -191,45 +192,50 @@ class VoxCeleb(datasets.GeneratorBasedBuilder):
|
|
191 |
targets = (
|
192 |
["audio1", "audio2"] if self.config.name == "audio" else [self.config.name]
|
193 |
)
|
194 |
-
|
195 |
-
cred_pass = os.environ.get("HUGGING_FACE_VOX_CELEB_PASS")
|
196 |
creds_path = Path(
|
197 |
f"~/.huggingface/voxceleb_{self.VERSION}_credentials"
|
198 |
).expanduser()
|
199 |
|
200 |
-
if
|
201 |
if creds_path.exists():
|
202 |
with open(creds_path, "r") as creds:
|
203 |
-
|
204 |
else:
|
205 |
print(
|
206 |
-
"You need a
|
207 |
-
f"
|
208 |
)
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
saved_credentials = False
|
216 |
|
217 |
def save_credentials():
|
218 |
-
nonlocal saved_credentials,
|
219 |
if not saved_credentials:
|
220 |
creds_path.parent.mkdir(exist_ok=True)
|
221 |
with open(creds_path, "w") as creds:
|
222 |
-
json.dump(
|
223 |
saved_credentials = True
|
224 |
|
225 |
def download_custom(placeholder_url, path):
|
226 |
-
nonlocal dl_manager,
|
227 |
sources = _PLACEHOLDER_MAPS[placeholder_url]
|
228 |
tmp_paths = []
|
229 |
lengths = []
|
230 |
start_positions = []
|
231 |
for url in sources:
|
232 |
-
head = requests.head(url,
|
233 |
if head.status_code == 401:
|
234 |
raise ValueError("failed to authenticate with VoxCeleb host")
|
235 |
if head.status_code < 200 or head.status_code >= 300:
|
@@ -279,8 +285,7 @@ class VoxCeleb(datasets.GeneratorBasedBuilder):
|
|
279 |
zip(
|
280 |
sources,
|
281 |
tmp_paths,
|
282 |
-
repeat(
|
283 |
-
repeat(cred_pass),
|
284 |
start_positions,
|
285 |
lengths,
|
286 |
repeat(q),
|
|
|
18 |
|
19 |
import json
|
20 |
import os
|
21 |
+
from urllib.parse import urlparse, parse_qs
|
22 |
from getpass import getpass
|
23 |
from hashlib import sha256
|
24 |
from itertools import repeat
|
|
|
60 |
"""
|
61 |
|
62 |
_URL = "https://mm.kaist.ac.kr/datasets/voxceleb"
|
63 |
+
_REQ_URL = "https://cn01.mmai.io/keyreq/voxceleb"
|
64 |
|
65 |
_URLS = {
|
66 |
"video": {
|
67 |
+
"placeholder": "https://cn01.mmai.io/download/voxceleb?file=vox2_dev_mp4",
|
68 |
"dev": (
|
69 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_mp4_partaa",
|
70 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_mp4_partab",
|
71 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_mp4_partac",
|
72 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_mp4_partad",
|
73 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_mp4_partae",
|
74 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_mp4_partaf",
|
75 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_mp4_partag",
|
76 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_mp4_partah",
|
77 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_mp4_partai",
|
78 |
),
|
79 |
+
"test": "https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_test_mp4.zip",
|
80 |
},
|
81 |
"audio1": {
|
82 |
+
"placeholder": "https://cn01.mmai.io/download/voxceleb?file=vox1_dev_wav",
|
83 |
"dev": (
|
84 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox1_dev_wav_partaa",
|
85 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox1_dev_wav_partab",
|
86 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox1_dev_wav_partac",
|
87 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox1_dev_wav_partad",
|
88 |
),
|
89 |
+
"test": "https://cn01.mmai.io/download/voxceleb?key={key}&file=vox1_test_wav.zip",
|
90 |
},
|
91 |
"audio2": {
|
92 |
+
"placeholder": "https://cn01.mmai.io/download/voxceleb?file=vox2_dev_aac",
|
93 |
"dev": (
|
94 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_aac_partaa",
|
95 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_aac_partab",
|
96 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_aac_partac",
|
97 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_aac_partad",
|
98 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_aac_partae",
|
99 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_aac_partaf",
|
100 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_aac_partag",
|
101 |
+
"https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_dev_aac_partah",
|
102 |
),
|
103 |
+
"test": "https://cn01.mmai.io/download/voxceleb?key={key}&file=vox2_test_aac.zip",
|
104 |
},
|
105 |
}
|
106 |
|
|
|
116 |
def _mp_download(
|
117 |
url,
|
118 |
tmp_path,
|
119 |
+
cred_key,
|
|
|
120 |
resume_pos,
|
121 |
length,
|
122 |
queue,
|
|
|
128 |
if resume_pos != 0:
|
129 |
headers["Range"] = f"bytes={resume_pos}-"
|
130 |
response = requests.get(
|
131 |
+
url.format(key=cred_key), headers=headers, verify=False, stream=True
|
132 |
)
|
133 |
if response.status_code >= 200 and response.status_code < 300:
|
134 |
for chunk in response.iter_content(chunk_size=65536):
|
|
|
141 |
class VoxCeleb(datasets.GeneratorBasedBuilder):
|
142 |
"""VoxCeleb is an unlabled dataset consisting of short clips of human speech from interviews on YouTube"""
|
143 |
|
144 |
+
VERSION = datasets.Version("1.1.0")
|
145 |
|
146 |
BUILDER_CONFIGS = [
|
147 |
datasets.BuilderConfig(
|
|
|
192 |
targets = (
|
193 |
["audio1", "audio2"] if self.config.name == "audio" else [self.config.name]
|
194 |
)
|
195 |
+
cred_key = os.environ.get("HUGGING_FACE_VOX_CELEB_KEY")
|
|
|
196 |
creds_path = Path(
|
197 |
f"~/.huggingface/voxceleb_{self.VERSION}_credentials"
|
198 |
).expanduser()
|
199 |
|
200 |
+
if cred_key is None:
|
201 |
if creds_path.exists():
|
202 |
with open(creds_path, "r") as creds:
|
203 |
+
cred_key = json.load(creds)
|
204 |
else:
|
205 |
print(
|
206 |
+
"You need a key to access VoxCeleb directly.",
|
207 |
+
f"Fill out the form ({_REQ_URL}) and paste in any of the download links you receive in your email.",
|
208 |
)
|
209 |
+
cred_url = getpass("Paste any VoxCeleb download URL here: ")
|
210 |
+
cred_url_parsed = urlparse(cred_url)
|
211 |
+
if cred_url_parsed.scheme != 'https' or cred_url_parsed.hostname != 'cn01.mmai.io' or cred_url_parsed.path != '/download/voxceleb':
|
212 |
+
raise ValueError("couldn't parse as VoxCeleb download URL")
|
213 |
+
cred_url_query = parse_qs(cred_url_parsed.query)
|
214 |
+
if 'key' not in cred_url_query or len(cred_url_query['key']) != 1:
|
215 |
+
raise ValueError("couldn't find key in URL")
|
216 |
+
cred_key = cred_url_query['key'][0]
|
217 |
+
|
218 |
+
if not cred_key:
|
219 |
+
raise ValueError("could not find key to log in")
|
220 |
|
221 |
saved_credentials = False
|
222 |
|
223 |
def save_credentials():
|
224 |
+
nonlocal saved_credentials, cred_key, creds_path
|
225 |
if not saved_credentials:
|
226 |
creds_path.parent.mkdir(exist_ok=True)
|
227 |
with open(creds_path, "w") as creds:
|
228 |
+
json.dump(cred_key, creds)
|
229 |
saved_credentials = True
|
230 |
|
231 |
def download_custom(placeholder_url, path):
|
232 |
+
nonlocal dl_manager, cred_key
|
233 |
sources = _PLACEHOLDER_MAPS[placeholder_url]
|
234 |
tmp_paths = []
|
235 |
lengths = []
|
236 |
start_positions = []
|
237 |
for url in sources:
|
238 |
+
head = requests.head(url.format(key=cred_key), verify=False, timeout=5)
|
239 |
if head.status_code == 401:
|
240 |
raise ValueError("failed to authenticate with VoxCeleb host")
|
241 |
if head.status_code < 200 or head.status_code >= 300:
|
|
|
285 |
zip(
|
286 |
sources,
|
287 |
tmp_paths,
|
288 |
+
repeat(cred_key),
|
|
|
289 |
start_positions,
|
290 |
lengths,
|
291 |
repeat(q),
|