fix: trim chatterbox voice uploads over 30s in webui

This commit is contained in:
owen
2026-09-08 00:22:47 -05:00
parent 6aac9bcae9
commit 9c0f0fac4f
+16
View File
@@ -952,6 +952,22 @@ def api_chatterbox_upload():
loops = (6000 // len(seg)) + 1 loops = (6000 // len(seg)) + 1
seg = seg * loops seg = seg * loops
log.debug(f"Voice upload: looped clip to {len(seg)}ms") log.debug(f"Voice upload: looped clip to {len(seg)}ms")
if len(seg) > 30000:
trimmed = seg[:30000]
try:
from pydub.silence import detect_silence
search_start = max(0, 30000 - 1500)
silences = detect_silence(
seg[search_start:30000], min_silence_len=300, silence_thresh=-40
)
if silences:
cutoff_local = silences[0][0]
if cutoff_local > 100:
trimmed = seg[: search_start + cutoff_local]
except Exception:
pass
seg = trimmed
log.debug(f"Voice upload: trimmed clip to {len(seg)}ms")
buf = _io.BytesIO() buf = _io.BytesIO()
seg.export(buf, format="wav") seg.export(buf, format="wav")
audio_bytes = buf.getvalue() audio_bytes = buf.getvalue()