-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcompute_statistics.py
89 lines (77 loc) · 2.61 KB
/
compute_statistics.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
82
83
84
85
86
87
88
89
import numpy as np
import os
import hparams as hp
#from utils.files import get_files
from tqdm import tqdm
#from utils.util import remove_outlier
import glob
def get_files(path, extension='.wav') :
filenames = []
for filename in glob.iglob(f'{path}/**/*{extension}', recursive=True):
filenames += [filename]
return filenames
if __name__ == '__main__':
min_e = []
min_p = []
max_e = []
max_p = []
nz_min_p = []
nz_min_e = []
energy_path = os.path.join(hp.data_dir, 'energy')
pitch_path = os.path.join(hp.data_dir, 'pitch')
mel_path = os.path.join(hp.data_dir, 'mels')
energy_files = get_files(energy_path, extension='.npy')
pitch_files = get_files(pitch_path, extension='.npy')
mel_files = get_files(mel_path, extension='.npy')
assert len(energy_files) == len(pitch_files) == len(mel_files)
energy_vecs = []
for f in tqdm(energy_files):
e = np.load(f)
#e = remove_outlier(e)
energy_vecs.append(e)
min_e.append(e.min())
nz_min_e.append(e[e>0].min())
max_e.append(e.max())
nonzeros = np.concatenate([v[np.where(v != 0.0)[0]] for v in energy_vecs])
e_mean, e_std = np.mean(nonzeros), np.std(nonzeros)
print("Non zero Min Energy : {}".format(min(nz_min_e)))
print("Max Energy : {}".format(max(max_e)))
print("Energy mean : {}".format(e_mean))
print("Energy std: {}".format(e_std))
pitch_vecs = []
for f in tqdm(pitch_files):
p = np.load(f)
#p = remove_outlier(p)
pitch_vecs.append(p)
min_p.append(p.min())
nz_min_p.append(p[p > 0].min())
max_p.append(p.max())
nonzeros = np.concatenate([v[np.where(v != 0.0)[0]] for v in pitch_vecs])
f0_mean, f0_std = np.mean(nonzeros), np.std(nonzeros)
print("Min Pitch : {}".format(min(min_p)))
print("Non zero Min Pitch : {}".format(min(nz_min_p)))
print("Max Pitch : {}".format(max(max_p)))
print("Pitch mean : {}".format(f0_mean))
print("Pitch std: {}".format(f0_std))
np.save(
os.path.join(hp.data_dir, "e_mean.npy"),
e_mean.astype(np.float32),
allow_pickle=False,
)
np.save(
os.path.join(hp.data_dir, "e_std.npy"),
e_std.astype(np.float32),
allow_pickle=False,
)
np.save(
os.path.join(hp.data_dir, "f0_mean.npy"),
f0_mean.astype(np.float32),
allow_pickle=False,
)
np.save(
os.path.join(hp.data_dir, "f0_std.npy"),
f0_std.astype(np.float32),
allow_pickle=False,
)
#print("Min Energy : {}".format(min(min_e)))
#print("Min Pitch : {}".format(min(min_p)))