RVC-Boss/GPT-SoVITS · error · ValueError

{ref_audio_path} not exists

Error message

{ref_audio_path} not exists

What it means

ValueError raised when the provided ref_audio_path fails os.path.exists() at the moment the handler decides to (re)prime the reference audio. This is a plain wrong-path error: the path was supplied, is different from the cached one, but does not resolve to a file on disk.

Source

Thrown at GPT_SoVITS/TTS_infer_pack/TTS.py:1136

        if no_prompt_text and self.configs.use_vocoder:
            raise NO_PROMPT_ERROR("prompt_text cannot be empty when using SoVITS_V3")

        if ref_audio_path in [None, ""] and (
            (self.prompt_cache["prompt_semantic"] is None) or (self.prompt_cache["refer_spec"] in [None, []])
        ):
            raise ValueError(
                "ref_audio_path cannot be empty, when the reference audio is not set using set_ref_audio()"
            )

        ###### setting reference audio and prompt text preprocessing ########
        t0 = time.perf_counter()
        if (ref_audio_path is not None) and (
            ref_audio_path != self.prompt_cache["ref_audio_path"]
            or (self.is_v2pro and self.prompt_cache["refer_spec"][0][1] is None)
        ):
            if not os.path.exists(ref_audio_path):
                raise ValueError(f"{ref_audio_path} not exists")
            self.set_ref_audio(ref_audio_path)

        aux_ref_audio_paths = aux_ref_audio_paths if aux_ref_audio_paths is not None else []
        paths = set(aux_ref_audio_paths) & set(self.prompt_cache["aux_ref_audio_paths"])
        if not (len(list(paths)) == len(aux_ref_audio_paths) == len(self.prompt_cache["aux_ref_audio_paths"])):
            self.prompt_cache["aux_ref_audio_paths"] = aux_ref_audio_paths
            self.prompt_cache["refer_spec"] = [self.prompt_cache["refer_spec"][0]]
            for path in aux_ref_audio_paths:
                if path in [None, ""]:
                    continue
                if not os.path.exists(path):
                    print(i18n("音频文件不存在,跳过:"), path)
                    continue
                self.prompt_cache["refer_spec"].append(self._get_ref_spec(path))

        if not no_prompt_text:
            prompt_text = prompt_text.strip("\n")
            if prompt_text[-1] not in splits:

View on GitHub (pinned to d523079fc0)

Solutions

  1. Check the path: print/copy the exact ref_audio_path from the error and confirm the file exists (ls / dir).
  2. Use an absolute path to avoid working-directory ambiguity.
  3. If the source is a URL, download it to a local file first, then pass the local path.
  4. Sanitize user input (strip quotes/newlines/spaces) before passing, e.g. with tools.my_utils.clean_path.

Example fix

# before
handler.set_ref_audio("'ref.wav\n")  # ValueError: ... not exists

# after
import os
from tools.my_utils import clean_path
ref = os.path.abspath(clean_path(user_input))
if not os.path.exists(ref):
    raise SystemExit(f"download/provide {ref} first")
handler.set_ref_audio(ref)
Defensive patterns

Strategy: validation

Validate before calling

import os
ref = os.path.abspath(ref_audio_path) if ref_audio_path else None
if ref is None or not os.path.exists(ref):
    raise ValueError(f"reference audio not found: {ref_audio_path!r}")

Type guard

def is_valid_audio_path(p: str | None) -> bool:
    return bool(p) and os.path.exists(os.path.abspath(str(p).strip().strip('"\'')))

Prevention

When it happens

Trigger: Calling infer_batch/run/set_ref_audio with a path that doesn't exist — typo, relative path resolved against the wrong working directory, URL instead of local file, or a file deleted/renamed after the UI listing was built.

Common situations: Path contains a trailing quote/space from copy-paste (partly handled by clean_path elsewhere but not here); webui launched from a different cwd so relative paths break; file on a network mount that disconnected; user pastes an http:// URL where a local file is required.

Related errors


AI-assisted analysis of RVC-Boss/GPT-SoVITS@d523079fc0 (2026-08-15). Data as JSON: /api/errors/7dabf3f436796899. Report an issue: GitHub.