init
Browse files- filter_audio.py +20 -19
filter_audio.py
CHANGED
@@ -30,8 +30,21 @@ files = {
|
|
30 |
}
|
31 |
audio_loader = Audio()
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# remove broken audio files
|
34 |
-
|
35 |
for i in tqdm(list(range(line_no_start, line_no_end))):
|
36 |
if i not in files:
|
37 |
continue
|
@@ -47,23 +60,11 @@ for i in tqdm(list(range(line_no_start, line_no_end))):
|
|
47 |
if start < end < len(wav["array"]):
|
48 |
pass
|
49 |
else:
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
broken_files.append(audio_file)
|
54 |
-
print(f"found {len(broken_files)} broken files:")
|
55 |
-
if len(broken_files) > 0:
|
56 |
-
flag = input("delete the broken files? (y/n): ")
|
57 |
-
if flag == "y":
|
58 |
-
for audio_file in broken_files:
|
59 |
-
# delete broken audio file
|
60 |
-
if os.path.exists(audio_file):
|
61 |
-
os.remove(audio_file)
|
62 |
-
# delete corresponding feature file
|
63 |
-
line_no = os.path.basename(audio_file).split(".")[0]
|
64 |
-
try:
|
65 |
-
feature_file = files[int(line_no)]
|
66 |
-
if os.path.exists(feature_file):
|
67 |
-
os.remove(feature_file)
|
68 |
except Exception as e:
|
69 |
print(e)
|
|
|
|
|
|
|
|
30 |
}
|
31 |
audio_loader = Audio()
|
32 |
|
33 |
+
|
34 |
+
def delete_audio(target_audio_file):
|
35 |
+
if os.path.exists(target_audio_file):
|
36 |
+
os.remove(target_audio_file)
|
37 |
+
line_no = os.path.basename(target_audio_file).split(".")[0]
|
38 |
+
try:
|
39 |
+
feature_file = files[int(line_no)]
|
40 |
+
if os.path.exists(feature_file):
|
41 |
+
os.remove(feature_file)
|
42 |
+
except Exception as e:
|
43 |
+
print(e)
|
44 |
+
|
45 |
+
|
46 |
# remove broken audio files
|
47 |
+
n_broken_files = 0
|
48 |
for i in tqdm(list(range(line_no_start, line_no_end))):
|
49 |
if i not in files:
|
50 |
continue
|
|
|
60 |
if start < end < len(wav["array"]):
|
61 |
pass
|
62 |
else:
|
63 |
+
delete_audio(audio_file)
|
64 |
+
n_broken_files += 1
|
65 |
+
print(n_broken_files)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
except Exception as e:
|
67 |
print(e)
|
68 |
+
delete_audio(audio_file)
|
69 |
+
n_broken_files += 1
|
70 |
+
print(n_broken_files)
|