Spaces:
Sleeping
Sleeping
Upload infertest.py
Browse files- infertest.py +41 -18
infertest.py
CHANGED
@@ -26,6 +26,7 @@ tmp = os.path.join(now_dir, "TEMP")
|
|
26 |
shutil.rmtree(tmp, ignore_errors=True)
|
27 |
os.makedirs(tmp, exist_ok=True)
|
28 |
os.environ["TEMP"] = tmp
|
|
|
29 |
from lib.infer_pack.models import (
|
30 |
SynthesizerTrnMs256NSFsid,
|
31 |
SynthesizerTrnMs256NSFsid_nono,
|
@@ -119,8 +120,17 @@ def api_convert_voice():
|
|
119 |
input_audio_path = os.path.join(tmp, f"{spk_id}_input_audio.{filename.split('.')[-1]}")
|
120 |
file.save(input_audio_path)
|
121 |
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
print(output_path)
|
|
|
|
|
124 |
if os.path.exists(output_path):
|
125 |
return send_file(output_path, as_attachment=True)
|
126 |
else:
|
@@ -441,34 +451,47 @@ def cut_vocal_and_inst_yt(split_model):
|
|
441 |
logs.append("Audio splitting complete.")
|
442 |
yield "\n".join(logs), vocal, inst, vocal
|
443 |
|
444 |
-
def cut_vocal_and_inst(
|
445 |
logs = []
|
446 |
vocal_path = "output/result/audio.wav"
|
447 |
os.makedirs("output/result", exist_ok=True)
|
448 |
-
wavfile.write(vocal_path, audio_data[0], audio_data[1])
|
449 |
-
logs.append("Starting the audio splitting process...")
|
450 |
-
yield "\n".join(logs), None, None
|
451 |
command = f"demucs --two-stems=vocals -n {split_model} {vocal_path} -o output"
|
452 |
result = subprocess.Popen(command.split(), stdout=subprocess.PIPE, text=True)
|
453 |
-
for line in result.stdout:
|
454 |
-
|
455 |
-
|
456 |
print(result.stdout)
|
457 |
vocal = f"output/{split_model}/audio/vocals.wav"
|
458 |
inst = f"output/{split_model}/audio/no_vocals.wav"
|
459 |
-
logs.append("Audio splitting complete.")
|
460 |
-
|
461 |
-
|
462 |
-
def combine_vocal_and_inst(
|
|
|
|
|
463 |
os.makedirs("output/result", exist_ok=True)
|
464 |
-
vocal_path
|
465 |
output_path = "output/result/combine.mp3"
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
|
|
471 |
return output_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
|
473 |
def download_and_extract_models(urls):
|
474 |
logs = []
|
|
|
26 |
shutil.rmtree(tmp, ignore_errors=True)
|
27 |
os.makedirs(tmp, exist_ok=True)
|
28 |
os.environ["TEMP"] = tmp
|
29 |
+
split_model=htdemucs
|
30 |
from lib.infer_pack.models import (
|
31 |
SynthesizerTrnMs256NSFsid,
|
32 |
SynthesizerTrnMs256NSFsid_nono,
|
|
|
120 |
input_audio_path = os.path.join(tmp, f"{spk_id}_input_audio.{filename.split('.')[-1]}")
|
121 |
file.save(input_audio_path)
|
122 |
|
123 |
+
#split audio
|
124 |
+
cut_vocal_and_inst(input_audio_path)
|
125 |
+
print("audio splitting performed")
|
126 |
+
vocal_path = f"output/{split_model}/audio/vocals.wav"
|
127 |
+
inst = f"output/{split_model}/audio/no_vocals.wav"
|
128 |
+
|
129 |
+
output_path = convert_voice(spk_id, vocal_path, voice_transform)
|
130 |
+
output_path= combine_vocal_and_inst(output_path,inst)
|
131 |
print(output_path)
|
132 |
+
|
133 |
+
|
134 |
if os.path.exists(output_path):
|
135 |
return send_file(output_path, as_attachment=True)
|
136 |
else:
|
|
|
451 |
logs.append("Audio splitting complete.")
|
452 |
yield "\n".join(logs), vocal, inst, vocal
|
453 |
|
454 |
+
def cut_vocal_and_inst(audio_path):
|
455 |
logs = []
|
456 |
vocal_path = "output/result/audio.wav"
|
457 |
os.makedirs("output/result", exist_ok=True)
|
458 |
+
#wavfile.write(vocal_path, audio_data[0], audio_data[1])
|
459 |
+
#logs.append("Starting the audio splitting process...")
|
460 |
+
#yield "\n".join(logs), None, None
|
461 |
command = f"demucs --two-stems=vocals -n {split_model} {vocal_path} -o output"
|
462 |
result = subprocess.Popen(command.split(), stdout=subprocess.PIPE, text=True)
|
463 |
+
#for line in result.stdout:
|
464 |
+
# logs.append(line)
|
465 |
+
# yield "\n".join(logs), None, None
|
466 |
print(result.stdout)
|
467 |
vocal = f"output/{split_model}/audio/vocals.wav"
|
468 |
inst = f"output/{split_model}/audio/no_vocals.wav"
|
469 |
+
#logs.append("Audio splitting complete.")
|
470 |
+
|
471 |
+
|
472 |
+
def combine_vocal_and_inst(vocal_path, inst_path):
|
473 |
+
vocal_volume=1
|
474 |
+
inst_volume=1
|
475 |
os.makedirs("output/result", exist_ok=True)
|
476 |
+
# Assuming vocal_path and inst_path are now directly passed as arguments
|
477 |
output_path = "output/result/combine.mp3"
|
478 |
+
command = f'ffmpeg -y -i "{inst_path}" -i "{vocal_path}" -filter_complex [0:a]volume={inst_volume}[i];[1:a]volume={vocal_volume}[v];[i][v]amix=inputs=2:duration=longest[a] -map [a] -b:a 320k -c:a libmp3lame "{output_path}"'
|
479 |
+
result = subprocess.run(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
480 |
+
if result.stderr:
|
481 |
+
print("Error:", result.stderr.decode())
|
482 |
+
else:
|
483 |
+
print("Success:", result.stdout.decode())
|
484 |
return output_path
|
485 |
+
|
486 |
+
#def combine_vocal_and_inst(audio_data, vocal_volume, inst_volume):
|
487 |
+
# os.makedirs("output/result", exist_ok=True)
|
488 |
+
## output_path = "output/result/combine.mp3"
|
489 |
+
# inst_path = f"output/{split_model}/audio/no_vocals.wav"
|
490 |
+
#wavfile.write(vocal_path, audio_data[0], audio_data[1])
|
491 |
+
#command = f'ffmpeg -y -i {inst_path} -i {vocal_path} -filter_complex [0:a]volume={inst_volume}[i];[1:a]volume={vocal_volume}[v];[i][v]amix=inputs=2:duration=longest[a] -map [a] -b:a 320k -c:a libmp3lame {output_path}'
|
492 |
+
#result = subprocess.run(command.split(), stdout=subprocess.PIPE)
|
493 |
+
#print(result.stdout.decode())
|
494 |
+
#return output_path
|
495 |
|
496 |
def download_and_extract_models(urls):
|
497 |
logs = []
|