ComfyUI Node

String Filter

A tiny string cleaner that strips separators from your TTS script

By teddy1565·Created 5 months ago·Updated 5 months ago· 2
String Filter
    • filtered_string
    single_string
    delimiter
    is_escape_charfalse

    String Filter is the unglamorous utility in this pack: it splits a single string on a delimiter and joins the pieces back together with nothing, giving you a cleaned-up string. In a TTS → Whisper captioning workflow you often have script text full of line breaks, punctuation, or separators you don't want to leak into your subtitle segments - and this is the node that strips them out.

    How it works. It takes three inputs: single_string (the text to clean), delimiter (what to strip), and is_escape_char (a boolean, default false). The source builds a regex pattern [delimiter]+ and re.splits on it, then joins the pieces into one string. The is_escape_char flag matters when your delimiter uses ASCII escapes like \n, \t, or \" - flip it on and those get translated to their real characters before splitting, so you can strip literal newlines without pasting an actual line break into the field. One output: filtered_string (STRING).

    So "Hello\nworld\nagain" with delimiter \n and is_escape_char on becomes "Helloworldagain". Want to strip a set of punctuation? A delimiter of ,。 removes both. It's a sibling to the pack's StringToStringList node, which splits the same way but returns a list instead of re-joining - different outputs, same mechanics.

    Install. It ships 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 pypinyin, numpy, torchaudio, torch - heavy for a string utility, but they're shared across the pack. No model downloads.

    The gotcha: the delimiter isn't a plain literal - it's dropped straight into a regex character class. That means characters with special meaning inside a class, like \, ], or ^, need care, and the trailing + means runs of the delimiter collapse together (which is usually what you want anyway). If you're stripping something like a backslash, you may need to think about how it lands in the pattern. For ordinary punctuation and whitespace, it just works.

    Honest take: this is a small utility you won't reach for constantly, but when you need to normalize a TTS script before it hits the alignment nodes, it's exactly the right size - no learning curve, does one thing, and lives in the same pack as the rest of the pipeline.

    CategoryTTS2Whisper/Utils/String

    Inputs (3)

    NameTypeDefaultDescription
    single_stringSTRING
    delimiterSTRING
    is_escape_charBOOLEANfalseif use ascii escape char, must enable

    Outputs (1)

    NameTypeDescription
    filtered_stringSTRING