@@ -15,7 +15,7 @@ def post_process(
15
15
manual_x_pad : int ,
16
16
f0_mel_min : float ,
17
17
f0_mel_max : float ,
18
- manual_f0 : Optional [Union [np .ndarray , list ]]= None ,
18
+ manual_f0 : Optional [Union [np .ndarray , list ]] = None ,
19
19
) -> Tuple [np .ndarray , np .ndarray ]:
20
20
f0 = np .multiply (f0 , pow (2 , f0_up_key / 12 ))
21
21
# with open("test.txt","w")as f:f.write("\n".join([str(i)for i in f0.tolist()]))
@@ -28,10 +28,14 @@ def post_process(
28
28
list (range (delta_t )), manual_f0 [:, 0 ] * 100 , manual_f0 [:, 1 ]
29
29
)
30
30
shape = f0 [manual_x_pad * tf0 : manual_x_pad * tf0 + len (replace_f0 )].shape [0 ]
31
- f0 [manual_x_pad * tf0 : manual_x_pad * tf0 + len (replace_f0 )] = replace_f0 [:shape ]
31
+ f0 [manual_x_pad * tf0 : manual_x_pad * tf0 + len (replace_f0 )] = replace_f0 [
32
+ :shape
33
+ ]
32
34
# with open("test_opt.txt","w")as f:f.write("\n".join([str(i)for i in f0.tolist()]))
33
35
f0_mel = 1127 * np .log (1 + f0 / 700 )
34
- f0_mel [f0_mel > 0 ] = (f0_mel [f0_mel > 0 ] - f0_mel_min ) * 254 / (f0_mel_max - f0_mel_min ) + 1
36
+ f0_mel [f0_mel > 0 ] = (f0_mel [f0_mel > 0 ] - f0_mel_min ) * 254 / (
37
+ f0_mel_max - f0_mel_min
38
+ ) + 1
35
39
f0_mel [f0_mel <= 1 ] = 1
36
40
f0_mel [f0_mel > 255 ] = 255
37
41
f0_coarse = np .rint (f0_mel ).astype (np .int32 )
@@ -44,9 +48,9 @@ def __init__(
44
48
rmvpe_root : Path ,
45
49
is_half : bool ,
46
50
x_pad : int ,
47
- device = "cpu" ,
48
- window = 160 ,
49
- sr = 16000
51
+ device = "cpu" ,
52
+ window = 160 ,
53
+ sr = 16000 ,
50
54
):
51
55
self .rmvpe_root = rmvpe_root
52
56
self .is_half = is_half
@@ -60,30 +64,34 @@ def calculate(
60
64
x : np .ndarray ,
61
65
p_len : int ,
62
66
f0_up_key : int ,
63
- f0_method : Literal ['pm' , ' dio' , ' harvest' , ' crepe' , ' rmvpe' , ' fcpe' ],
67
+ f0_method : Literal ["pm" , " dio" , " harvest" , " crepe" , " rmvpe" , " fcpe" ],
64
68
filter_radius : Optional [Union [int , float ]],
65
- manual_f0 : Optional [Union [np .ndarray , list ]]= None ,
69
+ manual_f0 : Optional [Union [np .ndarray , list ]] = None ,
66
70
) -> Tuple [np .ndarray , np .ndarray ]:
67
71
f0_min = 50
68
72
f0_max = 1100
69
73
if f0_method == "pm" :
70
74
if not hasattr (self , "pm" ):
71
75
from .pm import PM
76
+
72
77
self .pm = PM (self .window , f0_min , f0_max , self .sr )
73
78
f0 = self .pm .compute_f0 (x , p_len = p_len )
74
79
elif f0_method == "dio" :
75
80
if not hasattr (self , "dio" ):
76
81
from .dio import Dio
82
+
77
83
self .dio = Dio (self .window , f0_min , f0_max , self .sr )
78
84
f0 = self .dio .compute_f0 (x , p_len = p_len )
79
85
elif f0_method == "harvest" :
80
86
if not hasattr (self , "harvest" ):
81
87
from .harvest import Harvest
88
+
82
89
self .harvest = Harvest (self .window , f0_min , f0_max , self .sr )
83
90
f0 = self .harvest .compute_f0 (x , p_len = p_len , filter_radius = filter_radius )
84
91
elif f0_method == "crepe" :
85
92
if not hasattr (self , "crepe" ):
86
93
from .crepe import CRePE
94
+
87
95
self .crepe = CRePE (
88
96
self .window ,
89
97
f0_min ,
@@ -95,8 +103,9 @@ def calculate(
95
103
elif f0_method == "rmvpe" :
96
104
if not hasattr (self , "rmvpe" ):
97
105
from .rmvpe import RMVPE
106
+
98
107
self .rmvpe = RMVPE (
99
- str (self .rmvpe_root / "rmvpe.pt" ),
108
+ str (self .rmvpe_root / "rmvpe.pt" ),
100
109
is_half = self .is_half ,
101
110
device = self .device ,
102
111
# use_jit=self.config.use_jit,
@@ -108,6 +117,7 @@ def calculate(
108
117
elif f0_method == "fcpe" :
109
118
if not hasattr (self , "fcpe" ):
110
119
from .fcpe import FCPE
120
+
111
121
self .fcpe = FCPE (
112
122
self .window ,
113
123
f0_min ,
@@ -120,7 +130,11 @@ def calculate(
120
130
raise ValueError (f"f0 method { f0_method } has not yet been supported" )
121
131
122
132
return post_process (
123
- self .sr , self .window , f0 , f0_up_key , self .x_pad ,
133
+ self .sr ,
134
+ self .window ,
135
+ f0 ,
136
+ f0_up_key ,
137
+ self .x_pad ,
124
138
1127 * log (1 + f0_min / 700 ),
125
139
1127 * log (1 + f0_max / 700 ),
126
140
manual_f0 ,
0 commit comments