-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathprocess_echoset.py
81 lines (69 loc) · 2.52 KB
/
process_echoset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
###
# Author: Kai Li
# Date: 2022-05-26 20:53:15
# Email: [email protected]
# LastEditTime: 2022-05-26 20:58:39
###
import argparse
import json
import os
import soundfile as sf
from tqdm import tqdm
from rich import print
def preprocess_one_dir(in_data_dir, out_dir, data_type):
"""Create .json file for one condition."""
mix_infos = []
s1_infos = []
s2_infos = []
in_dir = os.path.abspath(os.path.join(in_data_dir, data_type))
print("Process {} set...".format(data_type))
for root, dirs, files in os.walk(in_dir):
for file in files:
if file.endswith(".wav") and file.startswith("mix"):
file_path = os.path.join(root, file)
audio, _ = sf.read(file_path)
mix_infos.append((
file_path,
len(audio),
))
file_path = file_path.replace("mix", "spk1_reverb")
audio, _ = sf.read(file_path)
s1_infos.append((
file_path,
len(audio),
))
file_path = file_path.replace("spk1_raw", "spk2_reverb")
audio, _ = sf.read(file_path)
s2_infos.append((
file_path,
len(audio),
))
print("Process num: {}".format(len(mix_infos)), end="\r")
if not os.path.exists(os.path.join(out_dir, data_type)):
os.makedirs(os.path.join(out_dir, data_type))
with open(os.path.join(out_dir, data_type, "mix.json"), "w") as f:
json.dump(mix_infos, f, indent=4)
with open(os.path.join(out_dir, data_type, "s1.json"), "w") as f:
json.dump(s1_infos, f, indent=4)
with open(os.path.join(out_dir, data_type, "s2.json"), "w") as f:
json.dump(s2_infos, f, indent=4)
def preprocess_lrs2_audio(inp_args):
"""Create .json files for all conditions."""
for data_type in ["test"]:
preprocess_one_dir(
inp_args.in_dir, inp_args.out_dir, data_type
)
if __name__ == "__main__":
parser = argparse.ArgumentParser("LRS2 audio data preprocessing")
parser.add_argument(
"--in_dir",
type=str,
default=None,
help="Directory path of audio including tr, cv and tt",
)
parser.add_argument(
"--out_dir", type=str, default=None, help="Directory path to put output files"
)
args = parser.parse_args()
print(args)
preprocess_lrs2_audio(args)