Skip to content

Commit 737337b

Browse files
authored
Create ppg_resample_interpolate
1 parent a1a3368 commit 737337b

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

ppg_resample_interpolate

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import sys
2+
import numpy as np
3+
from scipy.interpolate import interp1d
4+
import os
5+
6+
7+
8+
9+
10+
############################# single file #############################
11+
# ppg_original = np.load('/home/v-jiewang/ContentANDStyle_Disentangle/ppg_spk_norm/assets_25_10ms/PPGs_VCTK105/p225/p225_001.npy')
12+
# print(ppg_original.shape) # 206 frame (206, 41)
13+
# print(ppg_original)
14+
# # np.savetxt()
15+
16+
# duration = ppg_original.shape[0] * shift_from
17+
# # print(duration) # 2.06 s 保留到小数点后1位?
18+
19+
# t = np.arange(0, duration, shift_from)
20+
# # print(t.shape)
21+
# t2 = np.arange(0, duration, shift_to)
22+
# # print(t2)
23+
24+
# ppg_val = interp1d(t, ppg_original,
25+
# kind='linear', axis=0, fill_value='extrapolate', copy=False,
26+
# assume_sorted=True)
27+
28+
# ppg_val_to = ppg_val(t2)
29+
# print(ppg_val_to.shape) # (129, 41)
30+
# print(ppg_val_to)
31+
############################# single file #############################
32+
33+
34+
35+
shift_from = 0.01 # 帧移 s
36+
shift_to = 0.016
37+
38+
############################# multiple file #############################
39+
ppg_dir = '/home/v-jiewang/ContentANDStyle_Disentangle/ppg_spk_norm/assets_25_10ms/PPGs_VCTK105'
40+
ppg_target_dir = '/home/v-jiewang/ContentANDStyle_Disentangle/ppg_spk_norm/assets_64_16ms/PPGs_VCTK105_64_16ms'
41+
for spk in os.listdir(ppg_dir):
42+
# print(spk)
43+
target_spk_dir = os.path.join(ppg_target_dir, spk)
44+
if not os.path.exists(target_spk_dir):
45+
os.makedirs(target_spk_dir)
46+
# print(target_spk_dir)
47+
for uttid in os.listdir(os.path.join(ppg_dir, spk)):
48+
print(uttid)
49+
ppg_original = np.load(os.path.join(ppg_dir, spk, uttid))
50+
# print("ppg_original shape[0]", ppg_original.shape)
51+
duration = ppg_original.shape[0] * shift_from
52+
t = np.arange(0, duration, shift_from)
53+
# print("t shape[0]", t.shape[0])
54+
t2 = np.arange(0, duration, shift_to)
55+
if t.shape[0] < ppg_original.shape[0]:
56+
diffe = ppg_original.shape[0] - t.shape[0]
57+
if diffe <= 1:
58+
ppg_original = ppg_original[:t.shape[0], :]
59+
else:
60+
diffe = t.shape[0] - ppg_original.shape[0]
61+
if diffe <= 1:
62+
t = t[:ppg_original.shape[0]]
63+
assert t.shape[0] == ppg_original.shape[0]
64+
65+
ppg_val = interp1d(t, ppg_original,
66+
kind='linear', axis=0, fill_value='extrapolate', copy=False,
67+
assume_sorted=True)
68+
ppg_val_to = ppg_val(t2)
69+
target_ppg_file_name = os.path.join(target_spk_dir, uttid)
70+
# print(target_ppg_file_name)
71+
np.save(os.path.join(target_spk_dir, uttid), ppg_val_to)
72+
73+
############################# multiple file #############################
74+
75+
76+
############################# original #############################
77+
# if __name__ == '__main__':
78+
# if len(sys.argv) != 3:
79+
# print('Usage: python3 %s sampling_rate_from sampling_rate_to <lf0_in.float32 >lf0_out.float32' %sys.argv[0])
80+
# exit(-1)
81+
82+
# sr_from = float(sys.argv[1])
83+
# sr_to = float(sys.argv[2])
84+
# lf0 = np.frombuffer(sys.stdin.buffer.read(),dtype='float32').copy()
85+
# t = np.arange(0,lf0.size)/sr_from
86+
87+
# voiced_mask = lf0>0
88+
# duration = lf0.size/sr_from
89+
# t2= np.arange(0,duration,1/sr_to)
90+
91+
# lf0[0] = lf0[voiced_mask][0]
92+
# lf0[-1] = lf0[voiced_mask][-1]
93+
# voiced_mask = lf0 > 0
94+
95+
# lf0_val = interp1d(t[voiced_mask], lf0[voiced_mask],
96+
# kind='linear', fill_value='extrapolate', copy=False,
97+
# assume_sorted=True)
98+
99+
# lf0_val_t2 = lf0_val(t2)
100+
# sys.stdout.buffer.write(lf0_val(t2).astype('float32').tobytes())
101+
############################# original #############################

0 commit comments

Comments
 (0)