Nodes/ComfyUI-AV-FunASR/AV Format to Subtitle
ComfyUI Node

AV Format to Subtitle

From ASR output to a proper SRT — AV Format to Subtitle

By avenstack·Created about a year ago·Updated about a year ago· 24
AV Format to Subtitle
  • asr_result
  • subtitle
text

Speech recognition gives you words and timestamps. A subtitle file gives you timed, punctuated sentences. Those are two different things, and this is the node that bridges them. It takes the raw output of AV ASR Timestamp (or AV Speech Timestamp) and formats it into an actual SRT subtitle string - the thing you then feed into AV Save Subtitles to get a file on disk.

The pack's whole subtitle pipeline is: audio → AV ASR Timestamp → this node → AV Save Subtitles. Everything upstream produces data; this is where it becomes something a video editor will accept.

How it works

The ASR result contains space-separated words plus a per-word timestamp list. That's fine for a transcript, useless as subtitles. This node's formatter (format.py) does the clever part:

  • It splits the text into sentences using jieba (Chinese word segmentation), breaking at punctuation when it finds it.
  • It aligns each sentence segment back to the recognized word list using Levenshtein edit distance - fuzzy matching, because the ASR's word boundaries rarely line up with clean sentence boundaries.
  • It converts the per-word timestamps into per-sentence HH:MM:SS,mmm ranges and emits standard SRT: a counter, start --> end, and the text.

So the output is a proper, viewable .srt - which is why this pack can honestly claim "audio to subtitle" and not just "audio to text."

The inputs

  • asr_result - required, type ASRRESULT. This comes straight from the asr_result output of the two ASR nodes. It's a pack-specific type, so you can't feed it arbitrary strings.
  • text - optional, default null. This is the interesting one. If you have the true transcript - a script you wrote, or a Whisper transcription you trust more than the Chinese-first Paraformer - pass it in here. The node will align your text to the timestamps instead of the ASR's raw output, so your subtitles get the correct wording and punctuation without re-running recognition. Leave it empty and it just formats whatever the ASR produced.

That optional text input is the pack's hidden superpower: it's a "fix the transcript without re-transcribing" escape hatch. Cheap and effective, since the alignment work is fast.

Caveats worth knowing

The alignment is heuristic, not magic. It works great on clean, well-spoken audio; on noisy recordings where the ASR misrecognizes heavily, the edit-distance matching can drift and you'll get sentences with slightly off timings. It's tuned for Chinese (jieba, Chinese punctuation); English subtitles work in principle but won't get the same treatment. And it doesn't guess punctuation - if you leave text null, the output reflects whatever the ASR gave, which is raw.

Installing and first run

cd ComfyUI/custom_nodes
git clone https://github.com/avenstack/ComfyUI-AV-FunASR.git
cd ComfyUI-AV-FunASR
pip install -r requirements.txt

then restart ComfyUI, or find "ComfyUI-AV-FunASR" in ComfyUI Manager. This node itself has no model of its own, but it won't run until you've downloaded the model files the ASR nodes need into ComfyUI/models/ASR/FunASR/iic/ - see the pack README for the exact folder names.

Troubleshooting

  • "asr_result" input is red / nothing connects - you must wire it from the asr_result output of AV ASR Timestamp or AV Speech Timestamp. No other node emits this type.
  • Subtitles have wrong wording - that's the ASR's transcript, not the formatter. Pass your own text into the text input to override it.
  • Timings feel off - alignment quality tracks audio quality. On messy audio, expect drift; on clean speech it's typically solid.

One node, two inputs, and suddenly the whole pack produces something you can ship.

CategoryAven/AV-FunASR

Inputs (2)

NameTypeDefaultDescription
asr_resultASRRESULT
textSTRING

Outputs (1)

NameTypeDescription
subtitleSTRING