ignore
Browse files- download_audio.py +15 -7
download_audio.py
CHANGED
@@ -3,12 +3,13 @@ import tarfile
|
|
3 |
import zipfile
|
4 |
import gzip
|
5 |
import traceback
|
6 |
-
import requests
|
7 |
from os.path import join as p_join
|
8 |
from tqdm import tqdm
|
9 |
from multiprocessing import Pool
|
10 |
from typing import Optional
|
11 |
from urllib3.connection import ConnectionError
|
|
|
12 |
|
13 |
import pandas as pd
|
14 |
|
@@ -16,7 +17,7 @@ import pandas as pd
|
|
16 |
url_metadata_s2s = "https://dl.fbaipublicfiles.com/seamless/data/seamless_align_nov2023_extension/seamless.dataset.metadata.public.enA-jaA.tsv.gz"
|
17 |
url_metadata_s2t = "https://dl.fbaipublicfiles.com/seamless/data/seamless.dataset.metadata.public.enA-jpn.withduration.tsv.gz"
|
18 |
cache_dir_root = "./download"
|
19 |
-
n_pool = 8
|
20 |
|
21 |
|
22 |
def wget(url: str, cache_dir: str, filename: Optional[str] = None):
|
@@ -24,9 +25,10 @@ def wget(url: str, cache_dir: str, filename: Optional[str] = None):
|
|
24 |
filename = os.path.basename(url) if not filename else filename
|
25 |
output_file = p_join(cache_dir, filename)
|
26 |
try:
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
except ConnectionError or KeyboardInterrupt:
|
31 |
traceback.print_exc()
|
32 |
os.remove(output_file)
|
@@ -77,8 +79,14 @@ def process_dataset(url_metadata):
|
|
77 |
) for _, r in df_metadata.iterrows()]
|
78 |
inputs = [x for x in inputs if not os.path.exists(p_join(cache_dir_root, "audio", x[1]))]
|
79 |
print(f"{len(inputs)} urls to download")
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
|
84 |
if __name__ == '__main__':
|
|
|
3 |
import zipfile
|
4 |
import gzip
|
5 |
import traceback
|
6 |
+
# import requests
|
7 |
from os.path import join as p_join
|
8 |
from tqdm import tqdm
|
9 |
from multiprocessing import Pool
|
10 |
from typing import Optional
|
11 |
from urllib3.connection import ConnectionError
|
12 |
+
import urllib.request
|
13 |
|
14 |
import pandas as pd
|
15 |
|
|
|
17 |
url_metadata_s2s = "https://dl.fbaipublicfiles.com/seamless/data/seamless_align_nov2023_extension/seamless.dataset.metadata.public.enA-jaA.tsv.gz"
|
18 |
url_metadata_s2t = "https://dl.fbaipublicfiles.com/seamless/data/seamless.dataset.metadata.public.enA-jpn.withduration.tsv.gz"
|
19 |
cache_dir_root = "./download"
|
20 |
+
n_pool = int(os.getenv("N_POOL", 8))
|
21 |
|
22 |
|
23 |
def wget(url: str, cache_dir: str, filename: Optional[str] = None):
|
|
|
25 |
filename = os.path.basename(url) if not filename else filename
|
26 |
output_file = p_join(cache_dir, filename)
|
27 |
try:
|
28 |
+
urllib.request.urlretrieve(url, output_file)
|
29 |
+
# with open(output_file, "wb") as f:
|
30 |
+
# r = requests.get(url)
|
31 |
+
# f.write(r.content)
|
32 |
except ConnectionError or KeyboardInterrupt:
|
33 |
traceback.print_exc()
|
34 |
os.remove(output_file)
|
|
|
79 |
) for _, r in df_metadata.iterrows()]
|
80 |
inputs = [x for x in inputs if not os.path.exists(p_join(cache_dir_root, "audio", x[1]))]
|
81 |
print(f"{len(inputs)} urls to download")
|
82 |
+
if n_pool == 1:
|
83 |
+
for url, filename in tqdm(inputs, total=len(inputs)):
|
84 |
+
flag = get_audio(url, filename)
|
85 |
+
if flag:
|
86 |
+
print(f"failed:\n{url}")
|
87 |
+
else:
|
88 |
+
with Pool(n_pool) as pool:
|
89 |
+
pool.starmap(get_audio, tqdm(inputs, total=len(inputs)))
|
90 |
|
91 |
|
92 |
if __name__ == '__main__':
|