1
- '''
1
+ """
2
2
v1
3
3
runtime\python.exe myinfer-v2-0528.py 0 "E:\codes\py39\RVC-beta\t odo-songs" "E:\codes\py39\logs\mi-test\a dded_IVF677_Flat_nprobe_7.index" harvest "E:\codes\py39\RVC-beta\output" "E:\codes\py39\t est-20230416b\weights\mi-test.pth" 0.66 cuda:0 True 3 0 1 0.33
4
4
v2
5
5
runtime\python.exe myinfer-v2-0528.py 0 "E:\codes\py39\RVC-beta\t odo-songs" "E:\codes\py39\t est-20230416b\logs\mi-test-v2\a added_IVF677_Flat_nprobe_1_v2.index" harvest "E:\codes\py39\RVC-beta\output_v2" "E:\codes\py39\t est-20230416b\weights\mi-test-v2.pth" 0.66 cuda:0 True 3 0 1 0.33
6
- '''
7
- import os ,sys ,pdb ,torch
6
+ """
7
+ import os , sys , pdb , torch
8
+
8
9
now_dir = os .getcwd ()
9
10
sys .path .append (now_dir )
10
11
import argparse
13
14
import torch
14
15
import tqdm as tq
15
16
from multiprocessing import cpu_count
17
+
18
+
16
19
class Config :
17
- def __init__ (self ,device ,is_half ):
20
+ def __init__ (self , device , is_half ):
18
21
self .device = device
19
22
self .is_half = is_half
20
23
self .n_cpu = 0
@@ -90,22 +93,23 @@ def device_config(self) -> tuple:
90
93
91
94
return x_pad , x_query , x_center , x_max
92
95
93
- f0up_key = sys .argv [1 ]
94
- input_path = sys .argv [2 ]
95
- index_path = sys .argv [3 ]
96
- f0method = sys .argv [4 ]#harvest or pm
97
- opt_path = sys .argv [5 ]
98
- model_path = sys .argv [6 ]
99
- index_rate = float (sys .argv [7 ])
100
- device = sys .argv [8 ]
101
- is_half = bool (sys .argv [9 ])
102
- filter_radius = int (sys .argv [10 ])
103
- resample_sr = int (sys .argv [11 ])
104
- rms_mix_rate = float (sys .argv [12 ])
105
- protect = float (sys .argv [13 ])
96
+
97
+ f0up_key = sys .argv [1 ]
98
+ input_path = sys .argv [2 ]
99
+ index_path = sys .argv [3 ]
100
+ f0method = sys .argv [4 ] # harvest or pm
101
+ opt_path = sys .argv [5 ]
102
+ model_path = sys .argv [6 ]
103
+ index_rate = float (sys .argv [7 ])
104
+ device = sys .argv [8 ]
105
+ is_half = bool (sys .argv [9 ])
106
+ filter_radius = int (sys .argv [10 ])
107
+ resample_sr = int (sys .argv [11 ])
108
+ rms_mix_rate = float (sys .argv [12 ])
109
+ protect = float (sys .argv [13 ])
106
110
print (sys .argv )
107
- config = Config (device ,is_half )
108
- now_dir = os .getcwd ()
111
+ config = Config (device , is_half )
112
+ now_dir = os .getcwd ()
109
113
sys .path .append (now_dir )
110
114
from vc_infer_pipeline import VC
111
115
from infer_pack .models import (
@@ -118,64 +122,96 @@ def device_config(self) -> tuple:
118
122
from fairseq import checkpoint_utils
119
123
from scipy .io import wavfile
120
124
121
- hubert_model = None
125
+ hubert_model = None
126
+
127
+
122
128
def load_hubert ():
123
129
global hubert_model
124
- models , saved_cfg , task = checkpoint_utils .load_model_ensemble_and_task (["hubert_base.pt" ],suffix = "" ,)
130
+ models , saved_cfg , task = checkpoint_utils .load_model_ensemble_and_task (
131
+ ["hubert_base.pt" ],
132
+ suffix = "" ,
133
+ )
125
134
hubert_model = models [0 ]
126
135
hubert_model = hubert_model .to (device )
127
- if (is_half ):hubert_model = hubert_model .half ()
128
- else :hubert_model = hubert_model .float ()
136
+ if is_half :
137
+ hubert_model = hubert_model .half ()
138
+ else :
139
+ hubert_model = hubert_model .float ()
129
140
hubert_model .eval ()
130
141
131
- def vc_single (sid ,input_audio ,f0_up_key ,f0_file ,f0_method ,file_index ,index_rate ):
132
- global tgt_sr ,net_g ,vc ,hubert_model ,version
133
- if input_audio is None :return "You need to upload an audio" , None
142
+
143
+ def vc_single (sid , input_audio , f0_up_key , f0_file , f0_method , file_index , index_rate ):
144
+ global tgt_sr , net_g , vc , hubert_model , version
145
+ if input_audio is None :
146
+ return "You need to upload an audio" , None
134
147
f0_up_key = int (f0_up_key )
135
- audio = load_audio (input_audio ,16000 )
148
+ audio = load_audio (input_audio , 16000 )
136
149
times = [0 , 0 , 0 ]
137
- if (hubert_model == None ):load_hubert ()
150
+ if hubert_model == None :
151
+ load_hubert ()
138
152
if_f0 = cpt .get ("f0" , 1 )
139
153
# audio_opt=vc.pipeline(hubert_model,net_g,sid,audio,times,f0_up_key,f0_method,file_index,file_big_npy,index_rate,if_f0,f0_file=f0_file)
140
- audio_opt = vc .pipeline (hubert_model ,net_g ,sid ,audio ,input_audio ,times ,f0_up_key ,f0_method ,file_index ,index_rate ,if_f0 ,filter_radius ,tgt_sr ,resample_sr ,rms_mix_rate ,version ,protect ,f0_file = f0_file )
154
+ audio_opt = vc .pipeline (
155
+ hubert_model ,
156
+ net_g ,
157
+ sid ,
158
+ audio ,
159
+ input_audio ,
160
+ times ,
161
+ f0_up_key ,
162
+ f0_method ,
163
+ file_index ,
164
+ index_rate ,
165
+ if_f0 ,
166
+ filter_radius ,
167
+ tgt_sr ,
168
+ resample_sr ,
169
+ rms_mix_rate ,
170
+ version ,
171
+ protect ,
172
+ f0_file = f0_file ,
173
+ )
141
174
print (times )
142
175
return audio_opt
143
176
144
177
145
178
def get_vc (model_path ):
146
- global n_spk ,tgt_sr ,net_g ,vc ,cpt ,device ,is_half ,version
147
- print ("loading pth %s" % model_path )
179
+ global n_spk , tgt_sr , net_g , vc , cpt , device , is_half , version
180
+ print ("loading pth %s" % model_path )
148
181
cpt = torch .load (model_path , map_location = "cpu" )
149
182
tgt_sr = cpt ["config" ][- 1 ]
150
- cpt ["config" ][- 3 ]= cpt ["weight" ]["emb_g.weight" ].shape [0 ]# n_spk
151
- if_f0 = cpt .get ("f0" ,1 )
183
+ cpt ["config" ][- 3 ] = cpt ["weight" ]["emb_g.weight" ].shape [0 ] # n_spk
184
+ if_f0 = cpt .get ("f0" , 1 )
152
185
version = cpt .get ("version" , "v1" )
153
186
if version == "v1" :
154
187
if if_f0 == 1 :
155
188
net_g = SynthesizerTrnMs256NSFsid (* cpt ["config" ], is_half = is_half )
156
189
else :
157
190
net_g = SynthesizerTrnMs256NSFsid_nono (* cpt ["config" ])
158
191
elif version == "v2" :
159
- if if_f0 == 1 :#
192
+ if if_f0 == 1 : #
160
193
net_g = SynthesizerTrnMs768NSFsid (* cpt ["config" ], is_half = is_half )
161
194
else :
162
195
net_g = SynthesizerTrnMs768NSFsid_nono (* cpt ["config" ])
163
196
del net_g .enc_q
164
197
print (net_g .load_state_dict (cpt ["weight" ], strict = False )) # 不加这一行清不干净,真奇葩
165
198
net_g .eval ().to (device )
166
- if (is_half ):net_g = net_g .half ()
167
- else :net_g = net_g .float ()
199
+ if is_half :
200
+ net_g = net_g .half ()
201
+ else :
202
+ net_g = net_g .float ()
168
203
vc = VC (tgt_sr , config )
169
- n_spk = cpt ["config" ][- 3 ]
204
+ n_spk = cpt ["config" ][- 3 ]
170
205
# return {"visible": True,"maximum": n_spk, "__type__": "update"}
171
206
172
207
173
208
get_vc (model_path )
174
209
audios = os .listdir (input_path )
175
210
for file in tq .tqdm (audios ):
176
- if file .endswith ('.wav' ):
177
- file_path = input_path + '/' + file
178
- wav_opt = vc_single (0 ,file_path ,f0up_key ,None ,f0method ,index_path ,index_rate )
179
- out_path = opt_path + '/' + file
211
+ if file .endswith (".wav" ):
212
+ file_path = input_path + "/" + file
213
+ wav_opt = vc_single (
214
+ 0 , file_path , f0up_key , None , f0method , index_path , index_rate
215
+ )
216
+ out_path = opt_path + "/" + file
180
217
wavfile .write (out_path , tgt_sr , wav_opt )
181
-
0 commit comments