{"record":{"id":"f031b3e3cf311cdf","repo":"RVC-Boss/GPT-SoVITS","slug":"error-f031b3","errorCode":null,"errorMessage":"音频加载失败","messagePattern":"音频加载失败","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"tools/my_utils.py","lineNumber":35,"sourceCode":"    try:\r\n        # https://github.com/openai/whisper/blob/main/whisper/audio.py#L26\r\n        # This launches a subprocess to decode audio while down-mixing and resampling as necessary.\r\n        # Requires the ffmpeg CLI and `ffmpeg-python` package to be installed.\r\n        file = clean_path(file)  # 防止小白拷路径头尾带了空格和\"和回车\r\n        if os.path.exists(file) is False:\r\n            raise RuntimeError(\"You input a wrong audio path that does not exists, please fix it!\")\r\n        out, _ = (\r\n            ffmpeg.input(file, threads=0)\r\n            .output(\"-\", format=\"f32le\", acodec=\"pcm_f32le\", ac=1, ar=sr)\r\n            .run(cmd=[\"ffmpeg\", \"-nostdin\"], capture_stdout=True, capture_stderr=True)\r\n        )\r\n    except Exception:\r\n        out, _ = (\r\n            ffmpeg.input(file, threads=0)\r\n            .output(\"-\", format=\"f32le\", acodec=\"pcm_f32le\", ac=1, ar=sr)\r\n            .run(cmd=[\"ffmpeg\", \"-nostdin\"], capture_stdout=True)\r\n        )  # Expose the Error\r\n        raise RuntimeError(i18n(\"音频加载失败\"))\r\n\r\n    return np.frombuffer(out, np.float32).flatten()\r\n\r\n\r\ndef clean_path(path_str: str):\r\n    if path_str.endswith((\"\\\\\", \"/\")):\r\n        return clean_path(path_str[0:-1])\r\n    path_str = path_str.replace(\"/\", os.sep).replace(\"\\\\\", os.sep)\r\n    return path_str.strip(\r\n        \" '\\n\\\"\\u202a\"\r\n    )  # path_str.strip(\" \").strip('\\'').strip(\"\\n\").strip('\"').strip(\" \").strip(\"\\u202a\")\r\n\r\n\r\ndef check_for_existance(file_list: list = None, is_train=False, is_dataset_processing=False):\r\n    files_status = []\r\n    if is_train == True and file_list:\r\n        file_list.append(os.path.join(file_list[0], \"2-name2text.txt\"))\r\n        file_list.append(os.path.join(file_list[0], \"3-bert\"))\r","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/RVC-Boss/GPT-SoVITS/blob/d523079fc05d9a8028d6085bffe4a2757c32abb6/tools/my_utils.py#L17-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Ensure ffmpeg is installed and on PATH (ffmpeg -version).","Re-encode problem files to standard wav 16-bit PCM before ingestion: ffmpeg -i in.ext -ar 32000 -ac 1 out.wav.","Validate files upfront: non-zero size, decodable header via soundfile.info(), before batch runs."],"exampleFix":"# before\n# RuntimeError: 音频加载失败  (cause hidden in stderr)\naudio = load_audio(\"clip.m4a\", 32000)\n\n# after: pre-convert exotic formats, verify ffmpeg\nimport shutil, subprocess\nassert shutil.which(\"ffmpeg\"), \"install ffmpeg\"\nsubprocess.run([\"ffmpeg\", \"-y\", \"-i\", \"clip.m4a\", \"-ar\", \"32000\", \"-ac\", \"1\", \"clip.wav\"], check=True)\naudio = load_audio(\"clip.wav\", 32000)","handlingStrategy":"retry","validationCode":"import shutil, subprocess\nassert shutil.which(\"ffmpeg\"), \"ffmpeg not installed / not on PATH\"\n# pre-convert non-wav inputs so decode never fails mid-run\nsubprocess.run([\"ffmpeg\", \"-y\", \"-i\", src, \"-ar\", str(sr), \"-ac\", \"1\", dst], check=True,\n               capture_output=True)","typeGuard":null,"tryCatchPattern":"try:\n    audio = load_audio(f, sr)\nexcept RuntimeError as e:  # 音频加载失败 — stderr above holds the cause\n    if looks_like_codec_issue(e):\n        f = transcode_to_wav(f, sr)  # ffmpeg re-encode\n        audio = load_audio(f, sr)\n    else:\n        raise","preventionTips":["Install ffmpeg and verify with `ffmpeg -version` inside the deploy environment (Docker too).","Normalize all training audio to wav PCM during ingestion.","Capture and log ffmpeg stderr so the generic message never hides the root cause."],"tags":["audio-io","ffmpeg","environment","training-data"],"backgroundTag":null,"analyzedSha":"d523079fc05d9a8028d6085bffe4a2757c32abb6","analyzedAt":"2026-08-15T01:06:46.402Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}