init
Browse files- filter_audio.py +2 -0
- push_s2s_translation.py +31 -31
filter_audio.py
CHANGED
@@ -37,6 +37,8 @@ for i in tqdm(list(range(line_no_start, line_no_end))):
|
|
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):
|
|
|
37 |
continue
|
38 |
i = loader(files[i])
|
39 |
for lang_side in [sides_rev[1], sides_rev[2]]:
|
40 |
+
if f"{lang_side}.path" not in i:
|
41 |
+
continue
|
42 |
audio_file = i[f"{lang_side}.path"]
|
43 |
start, end = i[f"{lang_side}.duration_start"], i[f"{lang_side}.duration_end"]
|
44 |
if os.path.exists(audio_file):
|
push_s2s_translation.py
CHANGED
@@ -50,37 +50,37 @@ data_dict.update(
|
|
50 |
audio_dataset = Dataset.from_dict(data_dict)
|
51 |
audio_dataset = audio_dataset.cast_column(f"{sides_rev[1]}.audio", Audio())
|
52 |
audio_dataset = audio_dataset.cast_column(f"{sides_rev[2]}.audio", Audio())
|
53 |
-
|
54 |
-
# remove instances with broken audio files
|
55 |
-
broken_files = []
|
56 |
-
for i in tqdm(range(len(audio_dataset))):
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
print(f"features (removed broken audio): {len(audio_dataset) - len(broken_files)}")
|
71 |
-
if len(broken_files) > 0:
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
valid_data_id = [i for i in range(len(audio_dataset)) if i not in broken_files]
|
83 |
-
audio_dataset_valid = audio_dataset.select(valid_data_id)
|
84 |
|
85 |
|
86 |
# trim the audio according to the duration
|
|
|
50 |
audio_dataset = Dataset.from_dict(data_dict)
|
51 |
audio_dataset = audio_dataset.cast_column(f"{sides_rev[1]}.audio", Audio())
|
52 |
audio_dataset = audio_dataset.cast_column(f"{sides_rev[2]}.audio", Audio())
|
53 |
+
#
|
54 |
+
# # remove instances with broken audio files
|
55 |
+
# broken_files = []
|
56 |
+
# for i in tqdm(range(len(audio_dataset))):
|
57 |
+
# try:
|
58 |
+
# a = audio_dataset[i]
|
59 |
+
# flag = True
|
60 |
+
# for side_id in sides_rev.keys():
|
61 |
+
# start = a[f"{sides_rev[side_id]}.duration_start"]
|
62 |
+
# end = a[f"{sides_rev[side_id]}.duration_end"]
|
63 |
+
# array = a[f"{sides_rev[side_id]}.audio"]["array"]
|
64 |
+
# flag = 0 < start < end < len(array)
|
65 |
+
# if not flag:
|
66 |
+
# broken_files.append(i)
|
67 |
+
# except LibsndfileError:
|
68 |
+
# broken_files.append(i)
|
69 |
+
# continue
|
70 |
+
# print(f"features (removed broken audio): {len(audio_dataset) - len(broken_files)}")
|
71 |
+
# if len(broken_files) > 0:
|
72 |
+
# print(f"found {len(broken_files)} broken files:")
|
73 |
+
# flag = input("delete the broken files? (y/n): ")
|
74 |
+
# if flag == "y":
|
75 |
+
# # remove broken files
|
76 |
+
# for i in broken_files:
|
77 |
+
# if os.path.exists(files[file_ids[i]]):
|
78 |
+
# os.remove(files[file_ids[i]])
|
79 |
+
# for side_id in sides_rev.keys():
|
80 |
+
# if os.path.exists(data_dict[f"{sides_rev[side_id]}.audio"][i]):
|
81 |
+
# os.remove(data_dict[f"{sides_rev[side_id]}.audio"][i])
|
82 |
+
# valid_data_id = [i for i in range(len(audio_dataset)) if i not in broken_files]
|
83 |
+
# audio_dataset_valid = audio_dataset.select(valid_data_id)
|
84 |
|
85 |
|
86 |
# trim the audio according to the duration
|