RVC-Boss/GPT-SoVITS · error · ValueError
搜索音频长度 ({search_len}) 必须大于等于参考音频长度 ({ref_len})
Error message
搜索音频长度 ({search_len}) 必须大于等于参考音频长度 ({ref_len}) What it means
ValueError from a torch.jit.script-ed helper find_best_audio_offset_fast used in the v2Pro streaming path: it computes the best alignment offset of a reference clip inside a longer search window via conv1d cross-correlation, which is only defined when search_audio is at least as long as reference_audio. The guard runs inside the scripted function, so shape violations fail deterministically instead of producing a confusing conv1d kernel-size error.
Source
Thrown at GPT_SoVITS/stream_v2pro.py:193
return refer, sv_emb
def extract_latent(self, ssl_content):
codes = self.vq_model.extract_latent(ssl_content)
return codes[0]
def forward(self, pred_semantic, text_seq, refer, sv_emb=None):
return self.vq_model(
pred_semantic, text_seq, refer, speed=1.0, sv_emb=sv_emb
)[0, 0]
@torch.jit.script
def find_best_audio_offset_fast(reference_audio: Tensor, search_audio: Tensor):
ref_len = len(reference_audio)
search_len = len(search_audio)
if search_len < ref_len:
raise ValueError(
f"搜索音频长度 ({search_len}) 必须大于等于参考音频长度 ({ref_len})"
)
# 使用F.conv1d计算原始互相关
reference_flipped = reference_audio.unsqueeze(0).unsqueeze(0)
search_padded = search_audio.unsqueeze(0).unsqueeze(0)
# 计算点积
dot_products = F.conv1d(search_padded, reference_flipped).squeeze()
if len(dot_products.shape) == 0:
dot_products = dot_products.unsqueeze(0)
# 计算参考音频的平方和
ref_squared_sum = torch.sum(reference_audio**2)
# 计算搜索音频每个位置的平方和(滑动窗口)
search_squared = search_audio**2View on GitHub (pinned to d523079fc0)
Solutions
- Ensure every search window passed in is >= the reference/overlap length — pad the final chunk with zeros to at least len(reference_audio) before the call.
- Skip cross-correlation for tail chunks shorter than the overlap and use them as-is (or truncate the reference to the chunk length).
- Double-check argument order and that both tensors are at the same sample rate/dtype.
- If you control overlap_len, reduce it so it never exceeds your minimum chunk size.
Example fix
# before
best = find_best_audio_offset_fast(ref_chunk, search) # ValueError when search shorter
# after
if len(search) < len(ref_chunk):
pad = torch.zeros(len(ref_chunk) - len(search), dtype=search.dtype)
search = torch.cat([search, pad])
best = find_best_audio_offset_fast(ref_chunk, search) Defensive patterns
Strategy: validation
Validate before calling
assert search_audio.shape[-1] >= reference_audio.shape[-1], (
f"search {search_audio.shape[-1]} < reference {reference_audio.shape[-1]}"
) Type guard
def valid_sola_pair(ref: torch.Tensor, search: torch.Tensor) -> bool:
return search.numel() >= ref.numel() and ref.dtype == search.dtype Prevention
- Pad final stream chunks with zeros to at least the overlap/reference length.
- Choose overlap_len smaller than the minimum chunk size you ever emit.
- Keep both tensors at the same sample rate and dtype before cross-correlation.
When it happens
Trigger: Calling find_best_audio_offset_fast(reference_audio, search_audio) (directly or via the v2Pro streaming decode that hunts overlap positions) with len(search_audio) < len(reference_audio) — e.g. the SOLA overlap window handed in is shorter than the overlap template taken from the previous chunk.
Common situations: Custom chunk sizes/overlap_len that make the tail chunk smaller than the overlap template; final chunk of a stream (is_final) shorter than the reference overlap; callers swapping argument order; sample-rate mismatch making lengths inconsistent.
Related errors
AI-assisted analysis of RVC-Boss/GPT-SoVITS@d523079fc0 (2026-08-15).
Data as JSON: /api/errors/3261d102171172fe.
Report an issue: GitHub.