init
Browse files- filter_audio.py +66 -0
- main.sh +15 -1
filter_audio.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
from os.path import join as p_join
|
4 |
+
from tqdm import tqdm
|
5 |
+
from typing import Dict
|
6 |
+
from glob import glob
|
7 |
+
|
8 |
+
from soundfile import LibsndfileError
|
9 |
+
from datasets import Audio
|
10 |
+
|
11 |
+
# dataset config
|
12 |
+
direction = os.getenv("DIRECTION", "enA-jaA")
|
13 |
+
sides = {i: n for n, i in enumerate(sorted(direction.split("-")), 1)}
|
14 |
+
sides_rev = {v: k for k, v in sides.items()}
|
15 |
+
cache_dir_audio = p_join("download", "audio", direction)
|
16 |
+
cache_dir_feature = p_join("download", "feature", direction)
|
17 |
+
os.makedirs(cache_dir_audio, exist_ok=True)
|
18 |
+
os.makedirs(cache_dir_feature, exist_ok=True)
|
19 |
+
line_no_start = int(os.getenv("LINE_NO_START", 0))
|
20 |
+
line_no_end = int(os.getenv("LINE_NO_END", 100000))
|
21 |
+
|
22 |
+
|
23 |
+
def loader(feature: str) -> Dict:
|
24 |
+
with open(feature) as f:
|
25 |
+
return json.load(f)
|
26 |
+
|
27 |
+
|
28 |
+
files = {
|
29 |
+
int(os.path.basename(i).replace(".json", "")): i for i in glob(p_join(cache_dir_feature, "*.json"))
|
30 |
+
}
|
31 |
+
audio_loader = Audio()
|
32 |
+
|
33 |
+
# remove broken audio files
|
34 |
+
broken_files = []
|
35 |
+
for i in tqdm(list(range(line_no_start, line_no_end))):
|
36 |
+
if i not in files:
|
37 |
+
continue
|
38 |
+
i = loader(files[i])
|
39 |
+
for lang_side in [sides_rev[1], sides_rev[2]]:
|
40 |
+
audio_file = i[f"{lang_side}.path"]
|
41 |
+
start, end = i[f"{lang_side}.duration_start"], i[f"{lang_side}.duration_end"]
|
42 |
+
if os.path.exists(audio_file):
|
43 |
+
try:
|
44 |
+
wav = audio_loader.decode_example({"path": audio_file, "bytes": None})
|
45 |
+
if start < end < len(wav["array"]):
|
46 |
+
pass
|
47 |
+
else:
|
48 |
+
broken_files.append(audio_file)
|
49 |
+
except LibsndfileError:
|
50 |
+
broken_files.append(audio_file)
|
51 |
+
print(f"found {len(broken_files)} broken files:")
|
52 |
+
if len(broken_files) > 0:
|
53 |
+
flag = input("delete the broken files? (y/n): ")
|
54 |
+
if flag == "y":
|
55 |
+
for audio_file in broken_files:
|
56 |
+
# delete broken audio file
|
57 |
+
if os.path.exists(audio_file):
|
58 |
+
os.remove(audio_file)
|
59 |
+
# delete corresponding feature file
|
60 |
+
line_no = os.path.basename(audio_file).split(".")[0]
|
61 |
+
try:
|
62 |
+
feature_file = files[int(line_no)]
|
63 |
+
if os.path.exists(feature_file):
|
64 |
+
os.remove(feature_file)
|
65 |
+
except Exception as e:
|
66 |
+
print(e)
|
main.sh
CHANGED
@@ -3,63 +3,77 @@
|
|
3 |
####################
|
4 |
export DIRECTION="enA-jaA"
|
5 |
|
|
|
6 |
export LINE_NO_START=0
|
7 |
export LINE_NO_END=25000
|
8 |
python download_audio.py
|
9 |
|
10 |
-
|
11 |
export LINE_NO_START=25000
|
12 |
export LINE_NO_END=50000
|
13 |
python download_audio.py
|
14 |
|
|
|
15 |
export LINE_NO_START=50000
|
16 |
export LINE_NO_END=75000
|
17 |
python download_audio.py
|
18 |
|
|
|
19 |
export LINE_NO_START=75000
|
20 |
export LINE_NO_END=100000
|
21 |
python download_audio.py
|
22 |
|
|
|
23 |
export LINE_NO_START=100000
|
24 |
export LINE_NO_END=125000
|
25 |
python download_audio.py
|
26 |
|
|
|
27 |
export LINE_NO_START=125000
|
28 |
export LINE_NO_END=150000
|
29 |
python download_audio.py
|
30 |
|
|
|
31 |
export LINE_NO_START=150000
|
32 |
export LINE_NO_END=175000
|
33 |
python download_audio.py
|
34 |
|
|
|
35 |
export LINE_NO_START=175000
|
36 |
export LINE_NO_END=200000
|
37 |
python download_audio.py
|
38 |
|
|
|
39 |
export LINE_NO_START=200000
|
40 |
export LINE_NO_END=225000
|
41 |
python download_audio.py
|
42 |
|
|
|
43 |
export LINE_NO_START=225000
|
44 |
export LINE_NO_END=250000
|
45 |
python download_audio.py
|
46 |
|
|
|
47 |
export LINE_NO_START=250000
|
48 |
export LINE_NO_END=275000
|
49 |
python download_audio.py
|
50 |
|
|
|
51 |
export LINE_NO_START=275000
|
52 |
export LINE_NO_END=300000
|
53 |
python download_audio.py
|
54 |
|
|
|
55 |
export LINE_NO_START=300000
|
56 |
export LINE_NO_END=325000
|
57 |
python download_audio.py
|
58 |
|
|
|
59 |
export LINE_NO_START=325000
|
60 |
export LINE_NO_END=350000
|
61 |
python download_audio.py
|
62 |
|
|
|
63 |
export LINE_NO_START=350000
|
64 |
export LINE_NO_END=360000
|
65 |
python download_audio.py
|
|
|
3 |
####################
|
4 |
export DIRECTION="enA-jaA"
|
5 |
|
6 |
+
export DATASET_ID=1
|
7 |
export LINE_NO_START=0
|
8 |
export LINE_NO_END=25000
|
9 |
python download_audio.py
|
10 |
|
11 |
+
export DATASET_ID=2
|
12 |
export LINE_NO_START=25000
|
13 |
export LINE_NO_END=50000
|
14 |
python download_audio.py
|
15 |
|
16 |
+
export DATASET_ID=3
|
17 |
export LINE_NO_START=50000
|
18 |
export LINE_NO_END=75000
|
19 |
python download_audio.py
|
20 |
|
21 |
+
export DATASET_ID=4
|
22 |
export LINE_NO_START=75000
|
23 |
export LINE_NO_END=100000
|
24 |
python download_audio.py
|
25 |
|
26 |
+
export DATASET_ID=5
|
27 |
export LINE_NO_START=100000
|
28 |
export LINE_NO_END=125000
|
29 |
python download_audio.py
|
30 |
|
31 |
+
export DATASET_ID=6
|
32 |
export LINE_NO_START=125000
|
33 |
export LINE_NO_END=150000
|
34 |
python download_audio.py
|
35 |
|
36 |
+
export DATASET_ID=7
|
37 |
export LINE_NO_START=150000
|
38 |
export LINE_NO_END=175000
|
39 |
python download_audio.py
|
40 |
|
41 |
+
export DATASET_ID=8
|
42 |
export LINE_NO_START=175000
|
43 |
export LINE_NO_END=200000
|
44 |
python download_audio.py
|
45 |
|
46 |
+
export DATASET_ID=9
|
47 |
export LINE_NO_START=200000
|
48 |
export LINE_NO_END=225000
|
49 |
python download_audio.py
|
50 |
|
51 |
+
export DATASET_ID=10
|
52 |
export LINE_NO_START=225000
|
53 |
export LINE_NO_END=250000
|
54 |
python download_audio.py
|
55 |
|
56 |
+
export DATASET_ID=11
|
57 |
export LINE_NO_START=250000
|
58 |
export LINE_NO_END=275000
|
59 |
python download_audio.py
|
60 |
|
61 |
+
export DATASET_ID=12
|
62 |
export LINE_NO_START=275000
|
63 |
export LINE_NO_END=300000
|
64 |
python download_audio.py
|
65 |
|
66 |
+
export DATASET_ID=13
|
67 |
export LINE_NO_START=300000
|
68 |
export LINE_NO_END=325000
|
69 |
python download_audio.py
|
70 |
|
71 |
+
export DATASET_ID=14
|
72 |
export LINE_NO_START=325000
|
73 |
export LINE_NO_END=350000
|
74 |
python download_audio.py
|
75 |
|
76 |
+
export DATASET_ID=15
|
77 |
export LINE_NO_START=350000
|
78 |
export LINE_NO_END=360000
|
79 |
python download_audio.py
|