Communitygithub.com

動態字幕生成

當使用者要求「加入動態字幕」、「製作 TikTok 字幕」、「卡拉 OK 字幕」、「逐字字幕」、「自動字幕」、「突顯當前字詞」、「將字幕嵌入影片」或「將 SRT/逐字稿轉為動態文字」時,使用此技能。涵蓋 Whisper 的逐字時間戳、逐字彈入/縮放、當前字詞高亮度、9:16 安全區域擺放、易讀字型,以及嵌入式與外掛 SRT/VTT 字幕。

動態字幕生成 是什麼?

這個技能能將逐字稿或旁白轉換成逐字計時、極具吸引力的動態字幕,讓每個字在音節處彈出,當前字詞高亮度顯示,並與旁白精準同步。它專為 TikTok、Reels、Shorts 等短影音平台設計,確保字幕在 9:16 的垂直畫面中易於閱讀、節奏分明且位於安全區域內。此技能支援多種平台,包括 Remotion 和網頁端,並提供完整的處理流程:從使用 Whisper 進行語音辨識與逐字時間戳提取,到透過 Remotion 的 spring 動畫或 CSS 實現逐字彈入與高亮度效果,最後輸出嵌入式的 MP4 影片或外掛的 SRT/VTT 字幕檔。其核心原則是使用真實的逐字時間戳而非均分插值,並將易讀性置於風格之上,以粗體無襯線字型、厚重描邊或陰影來確保在任何背景下都清晰可見。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ItsMeMal/mallss3d-motion/tree/main/.claude/skills/caption-animation

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

動態字幕生成 是做什麼的?

將逐字稿或旁白轉換成逐字計時、令人目不轉睛的字幕:每個字在音節處彈出,當前字詞高亮度顯示,文字緊貼旁白。打造能提升 TikTok、Reels 和 Shorts 觀看時長的專業字幕 —— 易於閱讀、節奏分明,且位於安全區域內。

使用時機

  • 為短影音垂直影片(9:16)製作逐字或卡拉 OK 字幕。
  • 將逐字稿中的旁白/口白以開放式字幕燒錄到影片上。
  • 將 Whisper/SRT 逐字稿轉換為 Remotion 或網頁上的動態文字。
  • 將自動產生的字幕重新設計為具有品牌風格的「Hormozi 式」揭示效果。

處理流程

階段工作工具
語音轉寫音訊 → 逐字時間戳Whisper (@remotion/install-whisper-cpp), AssemblyAI
正規化→ { text, startMs, endMs }[] tokens@remotion/captions Caption 型別
分頁將單字分組為 1–4 個字的「頁面」createTikTokStyleCaptions()
動畫逐字彈入 + 當前字詞高亮度Remotion spring() / CSS
放置安全區域、易讀字型下方佈局規則
匯出嵌入 (MP4) 和/或外掛 SRT/VTTRemotion 渲染 / 檔案輸出

兩條不可妥協的規則

  1. 逐字時間戳,非逐行時間戳。 卡拉 OK 效果只有在每個字精準落在音節上時才顯得神奇。務必使用逐字時間戳進行轉寫;絕不要透過將一行文字平均分割到其持續時間來偽造時間戳 —— 偏移會立即被察覺。
  2. 易讀性優先於風格。 字幕是在手機上、陽光下、靜音狀態下閱讀的。優先使用粗體無襯線字型、厚重的描邊或陰影、高對比度;裝飾其次。沒人看得懂的字幕只是裝飾,不是字幕。

從逐字稿取得逐字時間戳

Whisper 可直接輸出逐字時間戳。將所有來源正規化為一個統一的 token 格式,讓渲染器無需關心文字來源:

// Caption token — 下游元件統一消費的格式
type Token = { text: string; startMs: number; endMs: number };

// 將 SRT cue 區塊 "00:00:01,200 --> 00:00:01,640" 解析為毫秒
const toMs = (t: string) => {
  const [h, m, rest] = t.split(":");
  const [s, ms] = rest.split(",");
  return ((+h * 60 + +m) * 60 + +s) * 1000 + +ms;
};

如果只有句子級別的線索,請重新進行逐字時間戳轉寫 —— 不要進行插值。Whisper 的 medium.en 模型速度約為 large 的 2 倍,且對於清晰的語音音訊已足夠準確。

逐字彈入效果 (Remotion)

讓每個字的縮放與透明度由一個錨定在其自身 startMs 的 spring 動畫驅動。微小的 overshoot 效果正是讓字幕「活起來」的關鍵。

import { useCurrentFrame, useVideoConfig, spring, interpolate } from "remotion";

const Word: React.FC<{ token: Token; active: boolean }> = ({ token, active }) => {
  const frame = useCurrentFrame();
  const { fps } = useVideoConfig();
  const enter = (token.startMs / 1000) * fps;            // 該字自己的進入影格
  const p = spring({ frame: frame - enter, fps, config: { damping: 12, mass: 0.6 } });
  const scale = interpolate(p, [0, 1], [0.6, 1]);        // 從 60% 彈入到 100%(包含 overshoot)
  return (
    <span style={{
      display: "inline-block",
      transform: `scale(${scale})`,
      opacity: interpolate(p, [0, 1], [0, 1]),
      color: active ? "#FFE45E" : "#FFFFFF",             // 當前字詞高亮度
      transition: "color 80ms linear",
    }}>{token.text}&nbsp;</span>
  );
};

透過比對當前 frame 與每個 token 的 [startMs, endMs] 來計算 active 狀態。將高亮度效果保持為單一強調色或當前字詞後方的實心「方塊」—— 絕不要同時對所有字的顏色進行動畫。

分頁而非文字牆

一次顯示 1–4 個字。使用 Remotion 的 createTikTokStyleCaptions()(或手動分組),並調整 combineTokensWithinMilliseconds 參數:約 200–500 毫秒適合真正的逐字顯示,約 1000–1500 毫秒則適合簡短易讀的短語。

import { createTikTokStyleCaptions } from "@remotion/captions";
const { pages } = createTikTokStyleCaptions({
  captions, combineTokensWithinMilliseconds: 1200,       // 每頁約 2–3 個字
});

網頁/CSS 彈入效果 (無 Remotion)

對於 DOM/即時播放器,為每個字設定其 animation-delay 等於 startMs:

.word { display:inline-block; opacity:0; animation: pop .26s cubic-bezier(.34,1.56,.64,1) forwards; }
@keyframes pop { from { opacity:0; transform:translateY(.18em) scale(.7) } to { opacity:1; transform:none } }
.word.active { color:#FFE45E; }
words.forEach(w => { const el = mk(w.text); el.style.animationDelay = `${w.startMs}ms`; track.append(el); });

易讀字型與安全區域擺放(9:16,1080×1920)

屬性數值原因
字型粗體/特粗無襯線 (Montserrat, Inter, Helvetica)在小而雜亂的螢幕上易於閱讀
大小56–80px(約畫面高度的 8%),最小 45px在手機上靜音觀看時依然清晰可辨
描邊2–6px 實心黑色輪廓在任何背景下都能突顯
陰影柔和的投射陰影作為描邊的備援在明亮影格上提供區隔
大小寫全大寫或句子大小寫;高對比填充力道 + 可掃讀性
垂直位置中間區域,約畫面 62–70% 處在 UI 上方、主要動作下方
底部安全區避開底部約 280px / 15% 區域避免遮到字幕/CTA/音訊 UI
側邊安全區保持在中央 80% 寬度內避免遮到右側欄圖示

將字幕放置在中間區域 —— 不要釘在最底部,那裡是平台 UI(使用者名稱、音訊、按鈕)所在的位置。將文字控制在最多約 2 行。

同步到旁白 / 口白

逐字稿本身就帶有精確音訊的時間資訊。將相同的音訊置於合成畫面下方,並保持時間戳基於音訊的時間基準 —— 字幕和聲音會自動鎖定,無需手動微調。如果 VO 重新錄製,請重新轉寫;絕不要用手動方式調整偏移。

嵌入 vs 外掛 SRT/VTT

嵌入 (開放式)外掛 SRT/VTT (封閉式)
位置MP4 中的圖元獨立的 .srt/.vtt 檔案
社群平台 (TikTok/Reels)必需 —— 保證顯示、可設定樣式常被平台忽略
無障礙 (ADA/WCAG)無法單獨滿足要求必需 (可切換)
最佳實務為社群平台燒錄動態字幕同時為網頁/SEO 提供外掛字幕

兩者都輸出:為社群平台燒錄動態字幕,並從相同的 tokens 產生純文字 SRT/VTT,以滿足無障礙/SEO 播放需求。

輸出檢查清單

  • 逐字時間戳(真實的,來自轉寫)—— 無均分插值偽造。
  • 逐字彈入效果,帶有微小的 overshoot;使用一個強調色作為當前字詞的高亮度。
  • 每頁 1–4 個字;絕不產生文字牆。
  • 粗體無襯線字型,56–80px,2–6px 描邊 + 陰影,高對比度。
  • 中間區域,避開底部約 280px 和側邊欄。
  • 音訊置於合成畫面下方;時間戳基於音訊時間基準。
  • 為社群平台輸出嵌入字幕,同時為無障礙播放提供外掛 SRT/VTT。

交付與驗證(渲染靜止影格 → MP4)

封裝好的輔助工具 (scripts/):使用 scripts/contact-sheet.sh sheet.png f-hook.png f-mid.png f-end.png 將靜止影格拼貼成聯絡表,然後用 scripts/probe-mp4.sh out.mp4 [WxH] [fps] 驗證編碼。詳見 scripts/README.md。

字幕以 Remotion 組合的形式交付(<Composition> + zod schema + defaultProps)—— 所有文字的運動均由 useCurrentFrame() 驅動的影格控制,絕不使用 Date.now() / Math.random() / 計時器。交付物 = out/*.mp4(已嵌入)+ 專案檔 + 外掛 SRT/VTT。預設為 9:16 垂直尺寸(1080×1920)。

驗證循環 —— 渲染靜止影格 → 檢查 → 編碼。 逐字時間戳是最容易出錯的部分;在花費時間進行完整編碼前,先在精確的影格點上檢查。

# 在開始 / 一個抽樣的當前字詞影格 / 結束處渲染靜止影格 —— 使用已交付的 props(真實 tokens + 音訊)
npx remotion still Captions out/f-start.png --frame=0   --props='{"captionsSrc":"vo.json"}'
npx remotion still Captions out/f-mid.png   --frame=90  --props='{"captionsSrc":"vo.json"}'
npx remotion still Captions out/f-end.png   --frame=N   --props='{"captionsSrc":"vo.json"}'  # N = durationInFrames-1

# 檢查每個 PNG:
#  - 在第 90 影格高亮顯示的字,其 [startMs,endMs] 應包含 90/fps(無偏移)
#  - 嵌入字幕清晰可讀:粗體無襯線、描邊+陰影效果良好、無裁切
#  - 9:16 安全區域:字幕位於中間區域,避開頂部約 12% 和底部約 20-35%(字幕/CTA/音訊 UI)以及右側操作欄

npx remotion render Captions out/captions.mp4 --props='{"captionsSrc":"vo.json"}'   # 靜止影格正確後再進行編碼
npx remotion render Captions out/demo.gif --codec=gif                                # README 展示片段

使用 npx remotion compositions 讀取 durationInFrames/fps,並選取當前字詞影格和結束影格。

完成前:

  1. 靜止影格在影格 0、中間的當前字詞影格和最後一個影格處清晰渲染 —— 無遺漏字型/音訊。
  2. 在抽樣的影格處正確高亮顯示對應的字(影格/fps 落在其 token 的時間範圍內);無均分插值偽造。
  3. 嵌入字幕清晰可讀(描邊+陰影),且字幕在每個檢查的影格中都完全位於 9:16 安全區域內。
  4. 僅由影格驅動 —— 無 Date.now() / Math.random() / 計時器。
  5. 已交付的 props(真實 tokens,不只是 defaultProps)能正確渲染;輸出 MP4 + 外掛 SRT/VTT,GIF 為選項。

參考檔案

  • references/word-timed-captions.md — 端到端建置:Whisper 轉寫與 Caption 型別、完整的 SRT 解析器、Remotion 逐字計時元件(含當前字詞高亮度)、手動分頁、SRT/VTT 輸出器、各平台安全區域對照表,以及易讀字型規格表。

Individual skills in this repo

This repo contains 3 individual skills — each has its own dedicated page.

short-form-video

This skill should be used when the user asks to "make a Reels/TikTok/YouTube Shorts video", "build a short-form video template", "write a hook for a short", "edit for retention", "add pattern interrupts", "make a video loop", "fix the first 3 seconds", "pace cuts for a vertical video", or "set up 9:16 safe areas". Covers the hook→retention→loop grammar of vertical short-form (distinct from a launch hype film).

talking-head-b-roll

Add b-roll motion graphics to a talking-head video. Transcribes the recording with word timings, decides line by line when the speaker is shown, when a graphic is laid over them and when a full-frame graphic covers them, draws each graphic from what is actually said (numbers, comparisons, steps, key words) in JavaScript on a canvas, and renders the finished MP4 with the original sound, plus the b-roll alone with alpha for an editor. Use when someone has a recording of a person talking to camera (a talking head, a spoken explainer, a course lesson, an ad read, a podcast clip) and wants it more engaging to watch, wants b-roll, or wants motion graphics added to it.

text-message-animation

This skill should be used when the user asks to "make a fake text message video", "animate an iMessage conversation", "create a text story video", "do a chat reply animation", "WhatsApp/SMS conversation video", "typing indicator animation", "render a chat thread to a video", or "batch text-message videos from a script/CSV". Covers sent/received bubble layout, staggered appear timing with typing indicators, read receipts/timestamps, per-message pop sound-sync, 9:16 safe-area, and data-driven render from a messages array.

相關技能