Nodes/ComfyUI-TTS2Whisper/Whisper Segments Alignment Merge
ComfyUI Node

Whisper Segments Alignment Merge

Uniform subtitle chunks from messy Whisper segments

By teddy1565·Created 5 months ago·Updated 5 months ago· 2
Whisper Segments Alignment Merge
  • segments_alignment
  • segments_alignment
max_str_size30

Whisper rarely hands you subtitle-ready segments. You get word-level fragments, or sentences of wildly different lengths, and if you try to burn those straight into a caption bar it looks like the pacing was set by a metronome that's having a seizure. Whisper Segments Alignment Merge flattens all of that into uniform chunks: it joins every segment's text into one string, slices it into equal-size pieces, and spreads them evenly across the audio's total duration. Result - consistent-length caption lines at consistent intervals, which is what actually reads well on screen.

How it works. It takes the segments_alignment value (segments with start, end, value) and one integer, max_str_size (default 30, minimum 0) - the max characters per output chunk. The source concatenates every segment's text, then chunks it with text[i:i+max_str_size]. In parallel it computes the total time as the ceiling of the maximum end timestamp, divides that by the number of chunks to get an interval, and walks from the first segment's start creating new {start, end} pairs at that interval, cycling through the chunks. Output is a fresh segments_alignment with uniform segments.

Default of 30 is a reasonable caption-line length. If your text runs long per line - Chinese characters are denser, so you might want more - bump it up.

Install. It's in teddy1565/ComfyUI-TTS2Whisper. ComfyUI Manager: search "ComfyUI-TTS2Whisper", install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/teddy1565/ComfyUI-TTS2Whisper

Dependencies are light - pypinyin, numpy, torchaudio, torch - and this pack downloads no models of its own. The README is a one-line stub, so treat the source as the docs.

Where it gets fiddly (real, from the source):

  • It measures total time from 0.0s, not from the first segment's start. The code has a commented-out line that originally subtracted start_timestamp, and the shipped version subtracts zero. So if there's leading silence before your first segment, the chunk boundaries drift later into the audio. Trim the silence at the head of your clip before you transcribe.
  • The text chunks cycle with a modulo. If the audio duration produces more output segments than there are text chunks, the text starts repeating across segments. That happens when max_str_size is small relative to the segment count - bump the size up or merge fewer upstream segments.
  • The last chunk's end can overshoot the audio slightly, since each segment is exactly interval_time long. Usually harmless for subtitle burn-in.

Where it sits: Whisper ASR → Injector (fix text) → TimeFix (fix boundaries) → Merge → burn-in. Run it after the Injector so it's chunking your clean script text, and after TimeFix so the boundaries it's averaging are already sane. If you skip TimeFix, Merge will average out whatever gaps Whisper left, which is a small error that compounds on longer audio.

CategoryTTS2Whisper/InjectTools

Inputs (2)

NameTypeDefaultDescription
segments_alignmentwhisper_alignment
max_str_sizeINT30

Outputs (1)

NameTypeDescription
segments_alignmentwhisper_alignment