@@ -15,7 +15,7 @@ def post_process(
1515 manual_x_pad : int ,
1616 f0_mel_min : float ,
1717 f0_mel_max : float ,
18- manual_f0 : Optional [Union [np .ndarray , list ]]= None ,
18+ manual_f0 : Optional [Union [np .ndarray , list ]] = None ,
1919) -> Tuple [np .ndarray , np .ndarray ]:
2020 f0 = np .multiply (f0 , pow (2 , f0_up_key / 12 ))
2121 # 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(
2828 list (range (delta_t )), manual_f0 [:, 0 ] * 100 , manual_f0 [:, 1 ]
2929 )
3030 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+ ]
3234 # with open("test_opt.txt","w")as f:f.write("\n".join([str(i)for i in f0.tolist()]))
3335 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
3539 f0_mel [f0_mel <= 1 ] = 1
3640 f0_mel [f0_mel > 255 ] = 255
3741 f0_coarse = np .rint (f0_mel ).astype (np .int32 )
@@ -44,9 +48,9 @@ def __init__(
4448 rmvpe_root : Path ,
4549 is_half : bool ,
4650 x_pad : int ,
47- device = "cpu" ,
48- window = 160 ,
49- sr = 16000
51+ device = "cpu" ,
52+ window = 160 ,
53+ sr = 16000 ,
5054 ):
5155 self .rmvpe_root = rmvpe_root
5256 self .is_half = is_half
@@ -60,30 +64,34 @@ def calculate(
6064 x : np .ndarray ,
6165 p_len : int ,
6266 f0_up_key : int ,
63- f0_method : Literal ['pm' , ' dio' , ' harvest' , ' crepe' , ' rmvpe' , ' fcpe' ],
67+ f0_method : Literal ["pm" , " dio" , " harvest" , " crepe" , " rmvpe" , " fcpe" ],
6468 filter_radius : Optional [Union [int , float ]],
65- manual_f0 : Optional [Union [np .ndarray , list ]]= None ,
69+ manual_f0 : Optional [Union [np .ndarray , list ]] = None ,
6670 ) -> Tuple [np .ndarray , np .ndarray ]:
6771 f0_min = 50
6872 f0_max = 1100
6973 if f0_method == "pm" :
7074 if not hasattr (self , "pm" ):
7175 from .pm import PM
76+
7277 self .pm = PM (self .window , f0_min , f0_max , self .sr )
7378 f0 = self .pm .compute_f0 (x , p_len = p_len )
7479 elif f0_method == "dio" :
7580 if not hasattr (self , "dio" ):
7681 from .dio import Dio
82+
7783 self .dio = Dio (self .window , f0_min , f0_max , self .sr )
7884 f0 = self .dio .compute_f0 (x , p_len = p_len )
7985 elif f0_method == "harvest" :
8086 if not hasattr (self , "harvest" ):
8187 from .harvest import Harvest
88+
8289 self .harvest = Harvest (self .window , f0_min , f0_max , self .sr )
8390 f0 = self .harvest .compute_f0 (x , p_len = p_len , filter_radius = filter_radius )
8491 elif f0_method == "crepe" :
8592 if not hasattr (self , "crepe" ):
8693 from .crepe import CRePE
94+
8795 self .crepe = CRePE (
8896 self .window ,
8997 f0_min ,
@@ -95,8 +103,9 @@ def calculate(
95103 elif f0_method == "rmvpe" :
96104 if not hasattr (self , "rmvpe" ):
97105 from .rmvpe import RMVPE
106+
98107 self .rmvpe = RMVPE (
99- str (self .rmvpe_root / "rmvpe.pt" ),
108+ str (self .rmvpe_root / "rmvpe.pt" ),
100109 is_half = self .is_half ,
101110 device = self .device ,
102111 # use_jit=self.config.use_jit,
@@ -108,6 +117,7 @@ def calculate(
108117 elif f0_method == "fcpe" :
109118 if not hasattr (self , "fcpe" ):
110119 from .fcpe import FCPE
120+
111121 self .fcpe = FCPE (
112122 self .window ,
113123 f0_min ,
@@ -120,7 +130,11 @@ def calculate(
120130 raise ValueError (f"f0 method { f0_method } has not yet been supported" )
121131
122132 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 ,
124138 1127 * log (1 + f0_min / 700 ),
125139 1127 * log (1 + f0_max / 700 ),
126140 manual_f0 ,
0 commit comments