From e3ffc711b8bbb467e70a328f119a64d7088def2c Mon Sep 17 00:00:00 2001 From: james Date: Sat, 21 Mar 2026 11:25:38 -0700 Subject: [PATCH] Fixed rvc endpoint accepting files --- rvc/wrapper/api/endpoints/inference.py | 45 +++++++++++++++++--------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/rvc/wrapper/api/endpoints/inference.py b/rvc/wrapper/api/endpoints/inference.py index ed24481..2b6d52e 100644 --- a/rvc/wrapper/api/endpoints/inference.py +++ b/rvc/wrapper/api/endpoints/inference.py @@ -25,7 +25,7 @@ load_dotenv() @router.post("/inference") def inference( - input_audio: Path | UploadFile, + input_audio: UploadFile, modelpath: Path | UploadFile = Body( ..., @@ -49,21 +49,34 @@ def inference( protect: float = 0.33, ): print(res_type) - vc = VC() - vc.get_vc(modelpath) - tgt_sr, audio_opt, times, _ = vc.vc_inference( - sid, - input_audio, - f0_up_key, - f0_method, - f0_file, - index_file, - index_rate, - filter_radius, - resample_sr, - rms_mix_rate, - protect, - ) + + # Handle uploaded input_audio file + tmp_input_audio = tempfile.NamedTemporaryFile(suffix=".wav", delete=False) + input_bytes = input_audio.file.read() + tmp_input_audio.write(input_bytes) + tmp_input_audio.close() + input_audio_path = tmp_input_audio.name + + try: + vc = VC() + vc.get_vc(modelpath) + tgt_sr, audio_opt, times, _ = vc.vc_inference( + sid, + 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) print(times) if res_type == "blob":