bark text encode
Bark text encode
- text_model
- semantic_history
- encoded text
You type a sentence, Bark talks. Between those two events sits bark_text_encode, the least glamorous and most quietly important node in the pack. It takes your plain text and turns it into exactly the token array Bark's semantic stage is expecting - and if you get this wrong, everything downstream is garbage with extra steps.
What it's actually doing
Bark doesn't tokenize with a plain vocabulary. It uses the bert-base-multilingual-cased tokenizer (the same one the bark_loader text model pulled in), then does a few Bark-specific contortions:
- every token gets an offset of 10,048 added, so real text sits above Bark's 10,000 semantic tokens and never collides with them;
- the array is padded or truncated to exactly 256 tokens;
- if you pass in
semantic_history, that gets appended behind the text, padded with a special pad token; - and the whole thing ends with a dedicated "start inference" token that tells the semantic model "go."
That's the whole mechanism, and it's why you can't just feed a text prompt into bark_generate_semantic directly - the model genuinely needs this exact shape.
The inputs that matter
- text_model - from
bark_loader. This is what carries the tokenizer, so there's no separate tokenizer to set up. - prompt - the actual sentence(s) to speak, in a multiline box. It gets whitespace-normalized (multiple spaces/newlines collapsed), and if you exceed 256 tokens the tail is silently cut off. Rough rule of thumb: 256 tokens is somewhere in the 20-30 second range of speech, so keep prompts shorter than that or the ending gets lopped.
The one optional input is worth knowing:
- semantic_history - wire
load_speaker_npz's text output (or a previous run's semantic tokens) in here. This is how voice cloning works: the model uses that history as context and continues "in the same voice" instead of starting fresh. This is also your seed-free path to a consistent voice across generations - same speaker npz, same style.
Output is a single encoded text (BarkTextEncodings) array, and it plugs straight into bark_generate_semantic.
Install & gotchas
Same pack as everything else here - gitmylo/ComfyUI-audio-nodes, installable via ComfyUI Manager (search "Audio nodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/gitmylo/ComfyUI-audio-nodes
Then restart. The node needs the text model loaded, so bark_loader must have text set to large or small - set it to none and this node has nothing to work with.
Where people get burned
Silent truncation is the classic one. Long prompts get their tail chopped with only a console warning, so a perfectly-planned 40-second monologue can end mid-word with zero explanation. Keep prompts tight, or split them into two encodes. The other gotcha: because the encode is deterministic, it's the one node in the pipeline where you won't get variety by re-running it - the randomness all comes from the generation nodes downstream. Same prompt, same encode, but a different voice every run unless you pin the speaker history.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| text_model | BarkTextModel | โ | |
| prompt | STRING | โ | |
| semantic_historyopt | BarkSemanticTokens | โ |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| encoded text | BarkTextEncodings | โ |