RVC-Project / Retrieval-based-Voice-Conversion

in preparation...
MIT License
240 stars 37 forks source link

FileNotFoundError: [Errno 2] No such file or directory: 'rvc/lib/uvr5_pack/lib_v5/modelparams/4band_v2.json' when using UVR.uvr_wrapper() #7

Open wAIfu-DEV opened 7 months ago

wAIfu-DEV commented 7 months ago

Hi, getting this error when using the UVR.uvr_wrapper() function:

Loading UVR
Extracting vocals...
Traceback (most recent call last):
  File "C:\Users\jeje9\Desktop\rvc_test\rvc_test.py", line 27, in <module>
    for i in result:
  File "C:\Users\jeje9\Desktop\rvc_test\lib\site-packages\rvc\modules\uvr5\modules.py", line 49, in uvr_wrapper
    pre_fun = func(
  File "C:\Users\jeje9\Desktop\rvc_test\lib\site-packages\rvc\modules\uvr5\vr.py", line 31, in __init__
    mp = ModelParameters("rvc/lib/uvr5_pack/lib_v5/modelparams/4band_v2.json")
  File "C:\Users\jeje9\Desktop\rvc_test\lib\site-packages\rvc\lib\uvr5_pack\lib_v5\model_param_init.py", line 55, in __init__
    with open(config_path, "r") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'rvc/lib/uvr5_pack/lib_v5/modelparams/4band_v2.json'

Here is my code:

import os

from dotenv import load_dotenv
from rvc.modules.uvr5.modules import UVR

# downloaded uvr model from:
# https://github.com/TRvlvr/model_repo/releases/

cwd = os.getcwd()
load_dotenv(".env")

print("Loading UVR")
uvr = UVR()

print("Extracting vocals...")

result = uvr.uvr_wrapper(
    model_name="2_HP-UVR.pth",
    audio_path=cwd + "audio.wav",
    save_vocal_path=cwd + "vocal.wav",
    save_ins_path=cwd + "inst.wav",
    agg=10, 
    export_format="wav",
    temp_path=cwd + "tmp.wav")

for i in result:
    print(i)

I made sure to look at the path, and the file does exist, so I'm thinking it might be an issue with the expected CWD since the path is relative. For more info: I'm running python from a venv and using this command to run: ./Scripts/python.exe rvc_test.py from the C:\Users\jeje9\Desktop\rvc_test directory where the rvc_test.py file is

wAIfu-DEV commented 7 months ago

This indeed seems to be the cause of the crash. I took the liberty to add a print statement in the source code, right before the call to open() image And got the path: C:\Users\jeje9\Desktop\rvc_test\rvc\lib\uvr5_pack\lib_v5\modelparams\4band_v2.json when the correct path should have been: C:\Users\jeje9\Desktop\rvc_test\lib\site-packages\rvc\lib\uvr5_pack\lib_v5\modelparams\4band_v2.json

wAIfu-DEV commented 7 months ago

Manually setting the CWD of the python script using os.chdir() fixes the issue on my end.

import os
import pydub

cwd = os.getcwd()
ffmpeg_exec = cwd + "\\ffmpeg.exe" # or any other path to ffmpeg, as long as it is absolute and not relative.

pydub.AudioSegment.converter = ffmpeg_exec

from dotenv import load_dotenv
from rvc.modules.uvr5.modules import UVR

# downloaded model from:
# https://github.com/TRvlvr/model_repo/releases/

load_dotenv(".env")

print(cwd)

print("Loading UVR")
uvr = UVR()

print("Extracting vocals...")

os.chdir(cwd + "\\Lib\\site-packages")

result = uvr.uvr_wrapper(
    model_name="2_HP-UVR.pth",
    audio_path=cwd + "\\audio.wav",
    save_vocal_path=cwd + "\\vocal",
    save_ins_path=cwd + "\\inst",
    agg=5,
    export_format="wav",
    temp_path=cwd + "\\tmp")

for i in result:
    print(i)
Tps-F commented 6 months ago

Sorry it took me so long to notice. I haven't tested it on windows yet, I'll fix it again.