Fixed rvc endpoint accepting files
This commit is contained in:
@@ -25,7 +25,7 @@ load_dotenv()
|
|||||||
|
|
||||||
@router.post("/inference")
|
@router.post("/inference")
|
||||||
def inference(
|
def inference(
|
||||||
input_audio: Path | UploadFile,
|
input_audio: UploadFile,
|
||||||
modelpath: Path
|
modelpath: Path
|
||||||
| UploadFile = Body(
|
| UploadFile = Body(
|
||||||
...,
|
...,
|
||||||
@@ -49,21 +49,34 @@ def inference(
|
|||||||
protect: float = 0.33,
|
protect: float = 0.33,
|
||||||
):
|
):
|
||||||
print(res_type)
|
print(res_type)
|
||||||
vc = VC()
|
|
||||||
vc.get_vc(modelpath)
|
# Handle uploaded input_audio file
|
||||||
tgt_sr, audio_opt, times, _ = vc.vc_inference(
|
tmp_input_audio = tempfile.NamedTemporaryFile(suffix=".wav", delete=False)
|
||||||
sid,
|
input_bytes = input_audio.file.read()
|
||||||
input_audio,
|
tmp_input_audio.write(input_bytes)
|
||||||
f0_up_key,
|
tmp_input_audio.close()
|
||||||
f0_method,
|
input_audio_path = tmp_input_audio.name
|
||||||
f0_file,
|
|
||||||
index_file,
|
try:
|
||||||
index_rate,
|
vc = VC()
|
||||||
filter_radius,
|
vc.get_vc(modelpath)
|
||||||
resample_sr,
|
tgt_sr, audio_opt, times, _ = vc.vc_inference(
|
||||||
rms_mix_rate,
|
sid,
|
||||||
protect,
|
input_audio_path,
|
||||||
)
|
f0_up_key,
|
||||||
|
f0_method,
|
||||||
|
f0_file,
|
||||||
|
index_file,
|
||||||
|
index_rate,
|
||||||
|
filter_radius,
|
||||||
|
resample_sr,
|
||||||
|
rms_mix_rate,
|
||||||
|
protect,
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
# Clean up temporary input audio file
|
||||||
|
os.unlink(tmp_input_audio.name)
|
||||||
|
|
||||||
wavfile.write(wv := BytesIO(), tgt_sr, audio_opt)
|
wavfile.write(wv := BytesIO(), tgt_sr, audio_opt)
|
||||||
print(times)
|
print(times)
|
||||||
if res_type == "blob":
|
if res_type == "blob":
|
||||||
|
|||||||
Reference in New Issue
Block a user