使用本機 Whisper
一個腳本,三種後端,統一的輸出格式。下游的所有操作(裁切清單、字幕時間軸、同步檢查)都會讀取 <stem>.words.json:
[
{"w": "Your", "s": 0.02, "e": 0.27},
{"w": "AI", "s": 0.27, "e": 0.40}
]
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。三者中提供最佳的字詞時間戳記 |
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 上使用(無終端機)。請要求使用者上傳 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。
依據任務選擇模型
| 任務 | 建議模型 | 原因 |
|---|---|---|
| 字幕時間戳記、同步檢查 | large-v3-turbo(mlx 或 faster-whisper) | 小模型在相同音訊上,每個單詞可能會有 0.1 到 0.4 秒的時間偏差 |
| 轉錄文字、裁切清單、重拍偵測 | small.en 或 turbo | 文字品質相近;small.en 在 CPU 上速度較快 |
| 非英文內容 | large-v3-turbo 搭配 --lang <code> | .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 模型下,預估約為即時速度的 1/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 <code> 參數 |
| 單詞連在一起(例如 "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)。