Spaces:
Sleeping
Sleeping
Upload myinfer_latest.py
Browse files- myinfer_latest.py +16 -5
myinfer_latest.py
CHANGED
@@ -116,6 +116,12 @@ def cleanup_files(file_paths):
|
|
116 |
processed_audio_storage = {}
|
117 |
@app.route('/convert_voice', methods=['POST'])
|
118 |
def api_convert_voice():
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
print(request.form)
|
120 |
print(request.files)
|
121 |
spk_id = request.form['spk_id']+'.pth'
|
@@ -144,7 +150,7 @@ def api_convert_voice():
|
|
144 |
vocal_path = f"output/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"
|
145 |
inst = f"output/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"
|
146 |
|
147 |
-
output_path = convert_voice(spk_id, vocal_path, voice_transform)
|
148 |
output_path1= combine_vocal_and_inst(output_path,inst,unique_id)
|
149 |
|
150 |
processed_audio_storage[unique_id] = output_path1
|
@@ -174,7 +180,7 @@ def get_processed_audio(audio_id):
|
|
174 |
return jsonify({"error": "File not found."}), 404
|
175 |
|
176 |
|
177 |
-
def convert_voice(spk_id, input_audio_path, voice_transform):
|
178 |
get_vc(spk_id,0.5)
|
179 |
output_audio_path = vc_single(
|
180 |
sid=0,
|
@@ -187,7 +193,8 @@ def convert_voice(spk_id, input_audio_path, voice_transform):
|
|
187 |
filter_radius=3,
|
188 |
resample_sr=0,
|
189 |
rms_mix_rate=0.25,
|
190 |
-
protect=0.33 # Adjusted from protect_rate to protect to match the function signature
|
|
|
191 |
)
|
192 |
print(output_audio_path)
|
193 |
return output_audio_path
|
@@ -253,7 +260,8 @@ def vc_single(
|
|
253 |
filter_radius,
|
254 |
resample_sr,
|
255 |
rms_mix_rate,
|
256 |
-
protect
|
|
|
257 |
): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
|
258 |
global tgt_sr, net_g, vc, hubert_model, version, cpt
|
259 |
|
@@ -298,7 +306,10 @@ def vc_single(
|
|
298 |
else "Index not used."
|
299 |
)
|
300 |
print("writing to FS")
|
301 |
-
output_file_path = os.path.join("output", f"converted_audio_{sid}.wav") # Adjust path as needed
|
|
|
|
|
|
|
302 |
|
303 |
os.makedirs(os.path.dirname(output_file_path), exist_ok=True) # Create the output directory if it doesn't exist
|
304 |
print("create dir")
|
|
|
116 |
processed_audio_storage = {}
|
117 |
@app.route('/convert_voice', methods=['POST'])
|
118 |
def api_convert_voice():
|
119 |
+
if session.get('submitted'):
|
120 |
+
return jsonify({"error": "Form already submitted"}), 400
|
121 |
+
|
122 |
+
# Process the form here...
|
123 |
+
# Set the flag indicating the form has been submitted
|
124 |
+
session['submitted'] = True
|
125 |
print(request.form)
|
126 |
print(request.files)
|
127 |
spk_id = request.form['spk_id']+'.pth'
|
|
|
150 |
vocal_path = f"output/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"
|
151 |
inst = f"output/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"
|
152 |
|
153 |
+
output_path = convert_voice(spk_id, vocal_path, voice_transform,unique_id)
|
154 |
output_path1= combine_vocal_and_inst(output_path,inst,unique_id)
|
155 |
|
156 |
processed_audio_storage[unique_id] = output_path1
|
|
|
180 |
return jsonify({"error": "File not found."}), 404
|
181 |
|
182 |
|
183 |
+
def convert_voice(spk_id, input_audio_path, voice_transform,unique_id):
|
184 |
get_vc(spk_id,0.5)
|
185 |
output_audio_path = vc_single(
|
186 |
sid=0,
|
|
|
193 |
filter_radius=3,
|
194 |
resample_sr=0,
|
195 |
rms_mix_rate=0.25,
|
196 |
+
protect=0.33, # Adjusted from protect_rate to protect to match the function signature,
|
197 |
+
unique_id=unique_id
|
198 |
)
|
199 |
print(output_audio_path)
|
200 |
return output_audio_path
|
|
|
260 |
filter_radius,
|
261 |
resample_sr,
|
262 |
rms_mix_rate,
|
263 |
+
protect,
|
264 |
+
unique_id
|
265 |
): # spk_item, input_audio0, vc_transform0,f0_file,f0method0
|
266 |
global tgt_sr, net_g, vc, hubert_model, version, cpt
|
267 |
|
|
|
306 |
else "Index not used."
|
307 |
)
|
308 |
print("writing to FS")
|
309 |
+
#output_file_path = os.path.join("output", f"converted_audio_{sid}.wav") # Adjust path as needed
|
310 |
+
# Assuming 'unique_id' is passed to convert_voice function along with 'sid'
|
311 |
+
output_file_path = os.path.join("output", f"converted_audio_{sid}_{unique_id}.wav") # Adjust path as needed
|
312 |
+
|
313 |
|
314 |
os.makedirs(os.path.dirname(output_file_path), exist_ok=True) # Create the output directory if it doesn't exist
|
315 |
print("create dir")
|