Skip to content
中文

Captions and styled text

Captions and styled text are made in the edit script; no separate speech-recognition call is needed. This page strings together steps that the script reference documents one by one.

1. Where captions come from

SourceCallNotes
The voice in a clipAddCaptionsFromTranscript(captionTrack, clip, { style: { preset: "short-video" } })Uses the library’s automatic transcript of the audio or video, which has word timestamps and speakers, so captions line up word by word. No separate speech-recognition call is needed
A script the captions must match exactlyCaption from the voice, then AlignCaptions(captionTrack, script)The script’s words replace the recognised ones (fixing a misheard word, for example) and the timing stays aligned; the script’s punctuation is kept as written, so remove unwanted end punctuation from the script first
An existing SRT or VTTImportCaptions(captionTrack, text)Wording and punctuation are kept; only overlapping or too-brief timings are fixed
A caption file to deliverExportCaptions(captionTrack)

Captions follow subtitle conventions by default: 12 characters a line on a portrait canvas and 20 otherwise, 0.6–7 s on screen, no full stop at a line end, and in-points near a cut snap to it.

2. Styles: a preset or your own

ListTextStyles() lists every preset; apply one with style: { preset: "<id>" }. Caption presets:

idNameLook
short-videoShort-video captionsCentred, very large white text, heavy black outline, yellow word highlight
karaokeKaraokeBottom white text with a yellow highlight word by word
subtitle-outlineOutlinedWhite text with a black outline, no box
subtitle-blackBoxedWhite text on a translucent black box
news-captionNewsCompact white text on a dark box
minimal-captionMinimalSmall white text with a light shadow
top-captionTopPinned to the top edge so the subject below stays clear
boxed-wordWord boxWhite text with a black outline; the current word sits on a purple rounded box
pop-wordPopHeavy white text; the current word grows and turns yellow
fade-wordsWord fadeSoft-shadow white text; each word fades in as it is spoken
slide-upSlide upOutlined white text that slides in from below word by word
bounce-wordBounceOutlined white text; the current word springs up and turns cyan
typewriterTypewriterMonospace-feel white text on a translucent black box, revealed character by character
uppercase-impactUppercase impactVery large outlined white text, all caps, with extra tracking
cinemaCinemaPale cream text, wide tracking, loose line height, light shadow

short-video captions sit in the centre of the picture and overlap a title card, which is centred too; while a title card is on screen use a bottom style such as subtitle-outline.

Title presets: bold-outline, variety-yellow, neon, metal-gold, flame, candy, bubble, ice-blue, retro, handwritten, quote, blue-pop, outline-coral, mint, lavender, clean-title, soft-shadow.

To adjust a preset or write your own, the style fields are fontFamily, fontSize, fontWeight, color, fill (gradient), stroke / strokes (layered outlines), shadows, glow, background (box colour), highlightColor (word highlight), position (top, middle, bottom), margin, maxLines and align. For example style: { preset: "short-video", fontSize: 84, highlightColor: "#FF4D4F" }.

The rich style shape is also accepted, and it is what drives the word-by-word animations:

  • style.letterSpacing (pixels at a 1080-pixel frame height, -20..100, negative tightens), style.lineHeight (a multiple, 0.5..3), style.textTransform (none, uppercase, lowercase, capitalize; capitalize upper-cases each word’s first letter, so (hello becomes (Hello), plus the same-named flat fields.
  • border: { width, color, opacity, radius } draws an outline on the edge of the box hugging the text; radius defaults to background.borderRadius (flat border).
  • animation.style picks the word animation and animation.direction (left, right, up, down; default up) is read by slide only:
animation.styleMeaning
highlightThe current word takes active.font.color (#FFE600 if none), and any richer animation an earlier write set is cleared
karaokeSpoken words and the current one stay highlighted; words not yet spoken keep their colour
popThe current word grows from 1 to active.font.size over 120 ms and settles
fadeEach word fades from transparent to opaque over 200 ms from its own start; words not yet spoken are hidden
slideLike fade, sliding in 0.4 em from direction
bounceThe current word springs up (a 250 ms sine arc)
typewriterCharacters appear one by one
noneClears the highlight and the word animation
  • active describes the current word: active.font.color (its colour), active.font.background (a rounded box behind it), active.font.size (its size in 1080-pixel units, a zoom), active.font.opacity (folded into the colour’s opacity), and active.stroke / active.shadow (its own outline or shadow; "none" removes it). The flat equivalents are highlightColor, activeBackground, activeFontSize, activeStroke and activeShadow.

A single line can override its track: Update(id, { style: { animation: { style: "pop" } } }) changes only that line while the rest follows the track. Fields with no renderer yet are refused by name: font.style, font.background, top-level padding, background.wrap, style.wordSpacing, style.textDecoration and style.size.

3. Title cards, name straps and other templates

ListTextTemplates() lists templates and InsertTemplate(track, { template, start, slots }) inserts one. Put templates on a video track above the footage: AddTrack("video", { name: "Titles" }, 0), where index 0 is the top layer; a track added without index goes to the bottom, under the footage. Each template has a fixed length, the duration in seconds that ListTextTemplates() returns (4 s for the title card), and plays from start; start captions after it when they must not overlap.

idUse
title-cardOpening title with a subtitle
chapter-titleSection break
lower-thirdName and role strap
quote-cardA highlighted line
data-cardOne highlighted number
dialog-bubbleDialogue or reaction text
label-stripA short place or topic label
follow-outroClosing follow prompt and account name

4. A complete script

// Run inside a project script (the script of POST /cut/v1/projects/{project_id}:execute).
// Replace lib_main / dub with a library bound to the project and a voiced video that has a transcript.
const footage = AddTrack("video", { name: "Footage" });
const clip = Insert(footage, { type: "video", media: { libraryId: "lib_main", assetId: "dub" }, start: 0, length: 15 });
const captions = AddTrack("caption", { name: "Captions" });
AddCaptionsFromTranscript(captions, clip, { style: { preset: "subtitle-outline" } });
AlignCaptions(captions, "第一集 三年了,她终于回到了长安城"); // the dialogue as written, in the voice's language
const titles = AddTrack("video", { name: "Titles" }, 0); // index 0 is the top layer; a track added without index goes to the bottom, under the footage
InsertTemplate(titles, { template: "title-card", start: 0, slots: { title: "Episode 1", subtitle: "Season one" } });
Preview([1, 5]);

Next steps