RVC-Project / Retrieval-based-Voice-Conversion

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

TypeError: expected str, bytes or os.PathLike object, not NoneType #13

Closed alcoftTAO closed 6 months ago

alcoftTAO commented 6 months ago

I have this error when using vc.get_vc("/home/alcoft/Descargas/Modelos RVC/I4.0 V4/NEKOTSUBA_BI_VOICEVOX.pth").

This is the traceback:

Traceback (most recent call last):
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/LibI4/Python_AI/ai_server_all.py", line 1, in <module>
    import ai_server
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/LibI4/Python_AI/ai_server.py", line 721, in <module>
    start_server()
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/LibI4/Python_AI/ai_server.py", line 701, in start_server
    cb.LoadAllModels()
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/LibI4/Python_AI/chatbot_all.py", line 130, in LoadAllModels
    rvc.LoadModel()
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/LibI4/Python_AI/Inference/RVC_inference.py", line 27, in LoadModel
    vc.get_vc("/home/alcoft/Descargas/Modelos RVC/I4.0 V4/NEKOTSUBA_BI_VOICEVOX.pth")
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/I4.0_ENV/lib/python3.11/site-packages/rvc/modules/vc/modules.py", line 84, in get_vc
    index = get_index_path_from_model(sid)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alcoft/Projects/Multilang/TAO_I4.0/I4.0_ENV/lib/python3.11/site-packages/rvc/modules/vc/utils.py", line 12, in get_index_path_from_model
    for root, _, files in os.walk(os.getenv("index_root"), topdown=False)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen os>", line 343, in walk
TypeError: expected str, bytes or os.PathLike object, not NoneType

My code is:

from pathlib import Path
from scipy.io import wavfile
from rvc.modules.vc.modules import VC
import os
import torch
import json
import ai_config as cfg

device: str = "cpu"
vc: VC = VC()

def LoadModel() -> None:
    global device, vc

    if (not cfg.current_data.prompt_order.__contains__("rvc")):
        raise Exception("Model is not in 'prompt_order'.")

    if (cfg.current_data.rvc_method != "rmvpe" and cfg.current_data.rvc_method != "pm" and cfg.current_data.rvc_method != "harvest" and cfg.current_data.rvc_method != "crepe"):
        raise Exception("RVC method must be 'rmvpe', 'pm', 'harvest' or 'crepe'.")

    if (len(cfg.current_data.rvc_model_path) == 0):
        return

    device = "cuda" if (torch.cuda.is_available() and cfg.current_data.use_gpu_if_available and cfg.current_data.move_to_gpu.count("rvc") > 0) else "cpu"
    vc.config.device = device

    vc.get_vc("/home/alcoft/Descargas/Modelos RVC/I4.0 V4/NEKOTSUBA_BI_VOICEVOX.pth")

def __make_rvc__(audio_name: str, protect: float = 0.33, filter_radius: int = 3) -> bytes:
    LoadModel()

    tgt_sr, audio_opt, times, _ = vc.vc_single(1, Path(audio_name), f0_method = cfg.current_data.rvc_method, index_file = Path(cfg.current_data.rvc_index_path), filter_radius = filter_radius, protect = protect)

    output_file = "tmp_rvc_output_"
    output_file_id = 0
    output_file_path = output_file + str(output_file_id) + ".wav"

    while (os.path.exists(output_file_path)):
        output_file_id += 1
        output_file_path = output_file + str(output_file_id) + ".wav"

    wavfile.write(output_file_path, tgt_sr, audio_opt)

    with open(output_file_path, "wb") as f:
        audio_bytes = f.read()
        f.close()

    os.remove(output_file_path)
    return audio_bytes

def MakeRVC(data: str | dict[str]) -> bytes:
    if (type(data) == str):
        try:
            data = json.loads(data)
        except Exception as ex:
            raise Exception("[RVC] Data must be a dictionary or a JSON code. ERROR: " + str(ex))

    ddata = {
        "input": "",
        "protect": 0.33,
        "filter_radius": 3
    }

    try:
        ddata["input"] = data["input"]
    except:
        raise Exception("Unable to get audio path.")

    try:
        ddata["protect"] = float(data["protect"])
    except:
        pass

    try:
        ddata["filter_radius"] = int(data["filter_radius"])
    except:
        pass

    return __make_rvc__(ddata["input"], ddata["protect"], ddata["filter_radius"], ddata["method"])

My Python version is Python 3.11.6 and the model path is /home/alcoft/Descargas/Modelos RVC/I4.0 V4/NEKOTSUBA_BI_VOICEVOX.pth.

Can someone help me fix this?

mathewpan2 commented 6 months ago

You need a .env file, which you can create with rvc env create. Then you need to fill out the paths listed in the .env file, and load the env file with load_dotenv(). You can get the files you need from below (I recommend checking the web-ui repository for more info on setup ), your error is saying you don't have a path to the index file.

Preparation of other Pre-models

RVC requires other pre-models to infer and train.

#Download all needed models from https://huggingface.co/lj1995/VoiceConversionWebUI/tree/main/
python tools/download_models.py

Or just download them by yourself from our Huggingface space.

Here's a list of Pre-models and other files that RVC needs:


./assets/hubert/hubert_base.pt

./assets/pretrained 

./assets/uvr5_weights

Additional downloads are required if you want to test the v2 version of the model.

./assets/pretrained_v2

If you want to test the v2 version model (the v2 version model has changed the input from the 256 dimensional feature of 9-layer Hubert+final_proj to the 768 dimensional feature of 12-layer Hubert, and has added 3 period discriminators), you will need to download additional features

./assets/pretrained_v2