使用本地 Whisper
一个脚本,三种后端,一种输出格式。所有下游流程(剪辑列表、字幕时间、同步门控)都读取 <stem>.words.json:
[
{"w": "Your", "s": 0.02, "e": 0.27},
{"w": "AI", "s": 0.27, "e": 0.4}
]
w = 听到的单词,s/e = 开始/结束时间(秒)。
要求(Claude Code,在计算机上)
ffmpeg(任何构建版本):brew install ffmpeg/apt install ffmpeg- Python 3.9+
- 一种后端:
| 后端 | 安装命令 | 默认模型 | 使用场景 |
|---|---|---|---|
mlx | pip install mlx-whisper | mlx-community/whisper-large-v3-turbo | Apple Silicon。三种中单词TIMING最佳 |
faster-whisper | pip install faster-whisper | large-v3-turbo | Linux/Windows,或CUDA |
whisper-cpp | brew install whisper-cpp(二进制文件为 whisper-cli) | 无,需传递 --model | 不希望使用Python ML栈 |
whisper.cpp 模型下载(466 MB,英文):
mkdir -p ~/whisper-models
curl -L -o ~/whisper-models/ggml-small.en.bin \
https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-small.en.bin
安装检查(打印 auto 将使用的后端):
ffmpeg -version | head -1
python3 -c "import mlx_whisper" 2>/dev/null && echo mlx || \
python3 -c "import faster_whisper" 2>/dev/null && echo faster-whisper || \
command -v whisper-cli || echo "NO BACKEND: install one from the table"
在 Claude.ai 上不可用(无 shell)。请让用户上传 SRT 文件。
运行
python3 scripts/transcribe.py take.mov # auto 后端,英文
python3 scripts/transcribe.py take.mov --backend whisper-cpp --model ~/whisper-models/ggml-small.en.bin
python3 scripts/transcribe.py final.mp4 --out qa/ --words-per-cue 2
python3 scripts/transcribe.py interview.m4a --lang auto # 检测语言
它会首先使用 ffmpeg 提取 16 kHz 单声道音频,因此任何容器格式都支持(mov、mp4、m4a、wav)。
输出文件位于输入文件旁边,除非指定了 --out:
<stem>.words.json、<stem>.txt、<stem>.srt。
针对不同任务选择模型
| 任务 | 使用模型 | 原因 |
|---|---|---|
| 字幕提示TIMING、同步门控 | large-v3-turbo(mlx 或 faster-whisper) | 小模型在相同音频上每个单词会漂移 0.1 到 0.4 秒 |
| 转录文本、剪辑列表、重拍检测 | small.en 或 turbo | 文本质量接近;small.en 在 CPU 上快速 |
| 非英语 | large-v3-turbo 配合 --lang <代码> | .en 模型仅限英语 |
避免重做的规则
- 文本来自脚本,时间戳来自Whisper。 Whisper 会听错名称(例如将 Claude 听成 Cloud)。对于字幕,将脚本的单词对齐到
words.json并保留脚本拼写(edit-style 的tools/make_cues.py可以做到)。对于没有脚本的内容,保留一个固定映射({"cloud code": "Claude Code"})。 - 在脚本中将数字写成数字。 Whisper 输出
2,000而不是 "two thousand",因此拼写出来的脚本会无法对齐。 - 重新转录最终渲染以获得发布的 SRT 和任何同步检查。原始片段的时间戳在每次剪辑后都是错误的。
- 即使语音稍后开始,Whisper 也会将第一个单词的时间戳标记在 0.00 附近。 在修剪头部之前,需要从音频能量中找到真实的起始点,然后重新转录前 2 秒以确认第一个单词仍然存在。
- 长文件(超过约 30 分钟):所有三个后端都可以处理;在 Apple Silicon 上使用 turbo 模型大约为实时/10 倍速。如果有人在同一台机器上录制,请在
nice -n 15下运行。
故障处理
| 症状 | 解决方法 |
|---|---|
no local Whisper found | 从表格中安装一个后端 |
whisper-cpp needs --model | 下载一个 ggml 模型(如上所述)或设置 WHISPER_MODEL |
whisper-cli not found 但已安装 | 设置 WHISPER_BIN=/path/to/whisper-cli(launchd/cron 的 PATH 通常缺少 /opt/homebrew/bin) |
| 输出为空或 0 个单词 | 检查文件是否包含音频:ffprobe -v error -select_streams a -show_entries stream=codec_name -of csv=p=0 FILE |
| 语言错误/乱码 | 显式传递 --lang <代码> |
| 单词粘在一起("2,000files") | 某些构建版本的 whisper.cpp 的问题;对于时序工作请使用 mlx 或 faster-whisper |
要报告的输出
whisper-cpp: 17 words, 5.68s -> o/take.words.json / .txt / .srt
然后将 words.json 路径传递给下一个技能(edit-style、longform-edit、reel-captions)。