关于 transcribe
面向 Remotion 项目的音视频转录技能,可生成带逐词时间戳的字幕,并输出 JSON、SRT 或纯文本。提供本地 Whisper WebGPU 方案,以及付费的 ElevenLabs Scribe 云端备用方案。
主要功能
- 01逐词时间戳
- 02本地 Whisper WebGPU 转录
- 03ElevenLabs Scribe 备用方案
- 04输出 JSON、SRT 和纯文本
- 05字幕后续处理指引
适用场景
- 01为视频制作定时字幕
- 02将转录内容导出为 SRT
- 03依据词语时间点同步动画
- 04整理文本以供翻译
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ dojocodinglabs/ remotion-superpowers --skill transcribe安装后在 Claude Code 中输入/transcribe确认已加载。
详细介绍
转录:音频/视频转文本
帮助用户将音频或视频文件转录为文本,并提供精确时间戳。
加载 remotion-production 技能,以遵循 captions-workflow 规则(两种路线都要遵循,包括 Scribe 脚本),并加载官方 remotion-captions 技能。使用 Scribe 路线时,还要加载 ElevenLabs 官方 speech-to-text 技能。API 细节以官方技能为准。
工作流
1. 确定源文件
查找要转录的音频/视频文件:
ls public/ public/footage/ 2>/dev/null | grep -E '\.(mp3|wav|m4a|ogg|mp4|mov|webm)$'
如果有多个文件,请询问用户要转录哪个文件。分别转录每个源文件,时间戳以该文件的起始位置为准。
2. 转录为词级 JSON
以下每条路线都会生成相同的结果:一个 Caption[],其中每个词对应一个条目,并保存为 public/<source>.captions.json(例如 vo-scene1.captions.json)。第 4 步中的 SRT 和纯文本输出将由此生成。
| 路线 | 适用情况 | 执行方式 |
|---|---|---|
| A. 官方 whisper-webgpu(默认) | 有兼容的 GPU | 本地免费运行,无需密钥 |
| B. ElevenLabs Scribe(备用) | whisper-webgpu 无法运行:没有 GPU、CI、Linux arm64、许多虚拟机 | 在云端付费运行,需要 ELEVENLABS_API_KEY |
路线 A:whisper-webgpu
遵循官方 remotion-captions/transcribe-captions.md。它会编写一个使用 @remotion/whisper-webgpu 的 Node 脚本(依次调用 canUseWhisperWebGpu、downloadWhisperModel、loadWhisperModel、transcribe,然后调用 toCaptions({ whisperWebGpuOutput })),该脚本会使用 Mediabunny 解码音频或视频并保存 Caption JSON。英语默认使用 small.en 模型。对于其他语言,请使用多语言模型并传入 language:该工具不会自动检测语言。如果 canUseWhisperWebGpu() 报告不支持,请切换到路线 B。
路线 B:ElevenLabs Scribe
使用 Scribe v2 转录(timestamps_granularity: "word"),并通过 @remotion/elevenlabs 中的 elevenLabsTranscriptToCaptions() 转换(npx remotion add @remotion/elevenlabs)。脚本位于 captions-workflow 规则中。
- 如果尚未设置
ELEVENLABS_API_KEY,请在项目根目录运行npx -y @elevenlabs/cli@latest onboard init。切勿在聊天中向用户索要密钥。 - 这会将音频发送给 ElevenLabs 并消耗额度,因此请先告知用户。
- 它可以直接处理视频文件,会自动检测语言(也可以传入
language_code),还可以通过keyterms指定它可能会听错的名称(参阅官方speech-to-text技能)。
不要使用 ElevenLabs MCP speech_to_text 工具:它只会返回纯文本,不含时间戳。
3. 呈现转录结果
显示带时间戳的转录内容,并按易读的行分组:
Transcription: [filename]
[00:00:00 → 00:00:03] Welcome to our product demo
[00:00:03 → 00:00:07] Today we're going to show you how easy it is
[00:00:07 → 00:00:11] to create professional videos with code
...
Total duration: [X]s
Word count: [X] words
4. 输出格式
提供用户要求的内容:
JSON 字幕(始终提供):使用 @remotion/captions 中的 Caption 类型。每个条目都必须包含 timestampMs 和 confidence(两者均可为 null),且每个词的开头都要有一个空格:
[
{ "text": " Welcome", "startMs": 0, "endMs": 800, "timestampMs": 400, "confidence": 0.95 },
{ "text": " to", "startMs": 800, "endMs": 1000, "timestampMs": 900, "confidence": 0.98 },
{ "text": " our", "startMs": 1000, "endMs": 1200, "timestampMs": 1100, "confidence": 0.97 }
]
SRT 导出(用户需要 .srt 文件时提供,例如用于上传到 YouTube):官方字幕技能涵盖 SRT 导入,但不涵盖导出,因此请使用 @remotion/captions 中的 serializeSrt() 从 JSON 生成。它接收 lines,这是一个由多行组成的数组,每行都是一个字幕数组。先将词分组成字幕行:
// scripts/export-srt.ts: node scripts/export-srt.ts
import { serializeSrt, type Caption } from "@remotion/captions";
import { readFileSync, writeFileSync } from "node:fs";
const name = "vo-scene1";
const words: Caption[] = JSON.parse(readFileSync(`public/${name}.captions.json`, "utf8"));
// New line after 7 words, at a sentence end, or at a pause longer than 0.6 s
const lines: Caption[][] = [];
let line: Caption[] = [];
words.forEach((word, i) => {
line.push(word);
const next = words[i + 1];
if (!next || line.length >= 7 || /[.!?]$/.test(word.text) || next.startMs - word.endMs > 600) {
lines.push(line);
line = [];
}
});
writeFileSync(`public/${name}.srt`, serializeSrt({ lines }));
serializeSrt() 会将一个字幕条中的词直接拼接,不添加空格;这正合适,因为每个词的 text 已经以一个空格开头。每个字幕条的起始时间为首个词的 startMs,结束时间为末个词的 endMs。生成的结果为标准 SRT:
1
00:00:00,000 --> 00:00:03,200
Welcome to our product demo
2
00:00:03,200 --> 00:00:07,100
Today we're going to show you how easy it is
纯文本:拼接各词的 text 并去除首尾空白,不含时间戳:
Welcome to our product demo. Today we're going to show you how easy it is to create professional videos with code.
5. 常见用例
转录后,可考虑以下后续步骤:
- 添加字幕 → 运行
/add-captions;逐词 JSON 适用于所有样式,包括 TikTok 和卡拉 OK - 同步动画 → 使用逐词时间戳,在特定词语出现时触发视觉元素
- 编写脚本 → 编辑转录文本,将其作为新配音的基础
- 翻译 → 使用转录文本创建其他语言版本
- 内容再利用 → 提取关键引语,用于社交媒体短片
路线 A 完全在设备上运行,无需 API 密钥。路线 B 则会调用 ElevenLabs 云服务。