{"record":{"id":"cf0438c5b49f06ef","repo":"RVC-Boss/GPT-SoVITS","slug":"3-10-cf0438","errorCode":null,"errorMessage":"参考音频在3~10秒范围外，请更换！","messagePattern":"参考音频在3~10秒范围外，请更换！","errorType":"validation","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"GPT_SoVITS/inference_webui.py","lineNumber":855,"sourceCode":"    text = text.strip(\"\\n\")\r\n    # if (text[0] not in splits and len(get_first(text)) < 4): text = \"。\" + text if text_language != \"en\" else \".\" + text\r\n\r\n    print(i18n(\"实际输入的目标文本:\"), text)\r\n    zero_wav = np.zeros(\r\n        int(hps.data.sampling_rate * pause_second),\r\n        dtype=np.float16 if is_half == True else np.float32,\r\n    )\r\n    zero_wav_torch = torch.from_numpy(zero_wav)\r\n    if is_half == True:\r\n        zero_wav_torch = zero_wav_torch.half().to(device)\r\n    else:\r\n        zero_wav_torch = zero_wav_torch.to(device)\r\n    if not ref_free:\r\n        with torch.no_grad():\r\n            wav16k, sr = librosa.load(ref_wav_path, sr=16000)\r\n            if wav16k.shape[0] > 160000 or wav16k.shape[0] < 48000:\r\n                gr.Warning(i18n(\"参考音频在3~10秒范围外，请更换！\"))\r\n                raise OSError(i18n(\"参考音频在3~10秒范围外，请更换！\"))\r\n            wav16k = torch.from_numpy(wav16k)\r\n            if is_half == True:\r\n                wav16k = wav16k.half().to(device)\r\n            else:\r\n                wav16k = wav16k.to(device)\r\n            wav16k = torch.cat([wav16k, zero_wav_torch])\r\n            ssl_content = ssl_model.model(wav16k.unsqueeze(0))[\"last_hidden_state\"].transpose(1, 2)  # .float()\r\n            codes = vq_model.extract_latent(ssl_content)\r\n            prompt_semantic = codes[0, 0]\r\n            prompt = prompt_semantic.unsqueeze(0).to(device)\r\n\r\n    t1 = ttime()\r\n    t.append(t1 - t0)\r\n\r\n    if how_to_cut == i18n(\"凑四句一切\"):\r\n        text = cut1(text)\r\n    elif how_to_cut == i18n(\"凑50字一切\"):\r\n        text = cut2(text)\r","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/RVC-Boss/GPT-SoVITS/blob/d523079fc05d9a8028d6085bffe4a2757c32abb6/GPT_SoVITS/inference_webui.py#L837-L873","documentation":"Webui duplicate of the TTS.py reference-audio length guard: before extracting prompt semantic tokens with the SSL model, it verifies the 16 kHz reference waveform is 3-10 s (48000-160000 samples) and raises OSError (with a gr.Warning toast) when out of range. Quality of zero-shot cloning collapses outside this window, so it is enforced hard.","triggerScenarios":"Running inference in the Gradio webui (or the get_phones_and_bert pipeline in inference_webui.py) with a reference/prompt wav whose 16 kHz sample count is <48000 or >160000 and ref_free is False.","commonSituations":"Short 1-2 s mic recording used as reference; whole song / long narration used as reference; silent padding counted in duration; reference file replaced with a long one but UI not refreshed.","solutions":["Re-select or trim the reference audio to 3-10 seconds of actual speech (5-8 s ideal).","Use the built-in audio-slicing tool (tools/slicer2.py) to cut long material into valid reference clips.","Remove silence at head/tail so all of the counted duration is speech.","Pre-validate duration in your own scripts with soundfile/librosa before invoking the webui function."],"exampleFix":"# before\n# in webui: paste 20s song as 参考音频 -> OSError 参考音频在3~10秒范围外\n\n# after: trim with ffmpeg to 6s of speech\n# ffmpeg -i long.wav -ss 5 -t 6 -af silenceremove=start_periods=1:start_threshold=-45dB ref.wav","handlingStrategy":"validation","validationCode":"import librosa\ndur = librosa.get_duration(path=ref_wav_path)\nif not (3.0 <= dur <= 10.0):\n    raise ValueError(f\"reference audio {dur:.1f}s outside 3-10s window — trim or replace\")","typeGuard":null,"tryCatchPattern":"try:\n    prompt = get_cirm(wav16k)  # internal webui path\nexcept OSError as e:\n    if \"3~10\" in str(e):\n        gr.Warning(\"请更换3~10秒的参考音频\")\n        return","preventionTips":["Prepare reference clips at 5-8 s of actual speech before pasting into the webui.","Use ffmpeg silenceremove/sox to trim silence so duration equals speech duration.","Cut long recordings with tools/slicer2.py and pick a clean 3-10 s segment."],"tags":["reference-audio","audio-duration","webui","validation"],"backgroundTag":null,"analyzedSha":"d523079fc05d9a8028d6085bffe4a2757c32abb6","analyzedAt":"2026-08-15T01:06:46.402Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}