RVC-Boss/GPT-SoVITS · error · RuntimeError

音频加载失败

Error message

音频加载失败

What it means

RuntimeError raised in the except branch of load_audio(): the first ffmpeg decode attempt failed for some reason (missing ffmpeg binary, unsupported/corrupt codec, permission error, or the path error above being swallowed by the except), a second ffmpeg run is attempted with stderr visible, and then the generic 音频加载失败 ('audio loading failed') is raised. The real cause is whatever ffmpeg reported on stderr in the second attempt.

Source

Thrown at tools/my_utils.py:35

    try:
        # https://github.com/openai/whisper/blob/main/whisper/audio.py#L26
        # This launches a subprocess to decode audio while down-mixing and resampling as necessary.
        # Requires the ffmpeg CLI and `ffmpeg-python` package to be installed.
        file = clean_path(file)  # 防止小白拷路径头尾带了空格和"和回车
        if os.path.exists(file) is False:
            raise RuntimeError("You input a wrong audio path that does not exists, please fix it!")
        out, _ = (
            ffmpeg.input(file, threads=0)
            .output("-", format="f32le", acodec="pcm_f32le", ac=1, ar=sr)
            .run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True)
        )
    except Exception:
        out, _ = (
            ffmpeg.input(file, threads=0)
            .output("-", format="f32le", acodec="pcm_f32le", ac=1, ar=sr)
            .run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True)
        )  # Expose the Error
        raise RuntimeError(i18n("音频加载失败"))

    return np.frombuffer(out, np.float32).flatten()


def clean_path(path_str: str):
    if path_str.endswith(("\\", "/")):
        return clean_path(path_str[0:-1])
    path_str = path_str.replace("/", os.sep).replace("\\", os.sep)
    return path_str.strip(
        " '\n\"\u202a"
    )  # path_str.strip(" ").strip('\'').strip("\n").strip('"').strip(" ").strip("\u202a")


def check_for_existance(file_list: list = None, is_train=False, is_dataset_processing=False):
    files_status = []
    if is_train == True and file_list:
        file_list.append(os.path.join(file_list[0], "2-name2text.txt"))
        file_list.append(os.path.join(file_list[0], "3-bert"))

View on GitHub (pinned to d523079fc0)

Solutions

  1. Read the ffmpeg stderr printed by the second .run() — it names the actual failure; fix that (install ffmpeg, get a decodable file, free the lock).
  2. Ensure ffmpeg is installed and on PATH (ffmpeg -version).
  3. Re-encode problem files to standard wav 16-bit PCM before ingestion: ffmpeg -i in.ext -ar 32000 -ac 1 out.wav.
  4. Validate files upfront: non-zero size, decodable header via soundfile.info(), before batch runs.

Example fix

# before
# RuntimeError: 音频加载失败  (cause hidden in stderr)
audio = load_audio("clip.m4a", 32000)

# after: pre-convert exotic formats, verify ffmpeg
import shutil, subprocess
assert shutil.which("ffmpeg"), "install ffmpeg"
subprocess.run(["ffmpeg", "-y", "-i", "clip.m4a", "-ar", "32000", "-ac", "1", "clip.wav"], check=True)
audio = load_audio("clip.wav", 32000)
Defensive patterns

Strategy: retry

Validate before calling

import shutil, subprocess
assert shutil.which("ffmpeg"), "ffmpeg not installed / not on PATH"
# pre-convert non-wav inputs so decode never fails mid-run
subprocess.run(["ffmpeg", "-y", "-i", src, "-ar", str(sr), "-ac", "1", dst], check=True,
               capture_output=True)

Try / catch

try:
    audio = load_audio(f, sr)
except RuntimeError as e:  # 音频加载失败 — stderr above holds the cause
    if looks_like_codec_issue(e):
        f = transcode_to_wav(f, sr)  # ffmpeg re-encode
        audio = load_audio(f, sr)
    else:
        raise

Prevention

When it happens

Trigger: load_audio() where ffmpeg.input(...).run() throws: ffmpeg not installed / not on PATH, file exists but is not decodable (e.g. m4a with unsupported codec build, truncated download, 0-byte file), or the earlier not-exists RuntimeError is caught by this same broad except.

Common situations: ffmpeg missing in Docker/minimal Linux; 'clean' audio-less deployment where user first hits [16] and sees this message instead; corrupted upload; file locked by another process on Windows; odd container formats ffmpeg build lacks.

Related errors


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