Communitygithub.com

MadAppGang/claude-code

使用 OpenAI Whisper 進行音訊/視訊轉錄。涵蓋安裝、模型選擇、轉錄格式(SRT、VTT、JSON)、時間同步及說話者辨識。適用於轉錄媒體或產生字幕。

claude-code 是什麼?

此技能專注於使用 OpenAI Whisper 進行音訊與視訊的轉錄(transcription),是影片編輯工作流程中的關鍵工具。它支援三種主要安裝選項:標準的 openai-whisper(Python)、更快的 whisper.cpp(C++)以及 GPU 加速的 Insanely Fast Whisper,讓使用者能根據硬體效能與使用情境做出最佳選擇。技能詳細說明了不同模型(從 tiny 到 large-v3)在大小、VRAM 需求、準確度與速度上的權衡,並建議從 small 模型開始測試。除了基本轉錄指令,它還提供音訊萃取(使用 ffmpeg 將影片轉為 16kHz 單聲道 WAV)、多種輸出格式(SRT、VTT、JSON 含逐字時間戳)、時間同步轉換(例如轉換為 Final Cut Pro 相容的幀數時間)、以及進階的說話者辨識(使用 pyannote.audio)。此外,它也涵蓋批次處理腳本、雜訊抑制與語言提示等品質優化技巧,以及完整的錯誤處理驗證功能。此技能主要應用於影片後製、字幕生成、多媒體內容分析,並與 ffmpeg-core 和 final-cut-pro 等技能互補。

相容平台✓Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/MadAppGang/claude-code/tree/HEAD/plugins/video-editing/skills/transcription

在你喜歡的 AI 中提問

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

說明文件

plugin: video-editing updated: 2026-01-20

Whisper 轉錄技術

使用 OpenAI Whisper 進行音訊/視訊轉錄的生產級模式。

系統需求

安裝選項

選項 1:OpenAI Whisper(Python)

# macOS/Linux/Windows
pip install openai-whisper

# 驗證
whisper --help

選項 2:whisper.cpp(C++ - 更快)

# macOS
brew install whisper-cpp

# Linux - 從原始碼編譯
git clone https://github.com/ggerganov/whisper.cpp
cd whisper.cpp && make

# Windows - 使用預先編譯的二進位檔或 cmake 編譯

選項 3:Insanely Fast Whisper(GPU 加速)

pip install insanely-fast-whisper

模型選擇

模型大小VRAM準確度速度使用案例
tiny39M~1GB低最快快速預覽
base74M~1GB中等快草稿轉錄
small244M~2GB良好中等一般用途
medium769M~5GB較佳慢高品質轉錄
large-v31550M~10GB最佳最慢最終成品

建議: 從 small 開始以取得速度/品質平衡。最終交付時使用 large-v3。

基本轉錄

使用 OpenAI Whisper

# 基本轉錄(自動偵測語言)
whisper audio.mp3 --model small

# 指定語言和輸出格式
whisper audio.mp3 --model medium --language en --output_format srt

# 多種輸出格式
whisper audio.mp3 --model small --output_format all

# 含時間戳記和逐字時間
whisper audio.mp3 --model small --word_timestamps True

使用 whisper.cpp

# 先下載模型
./models/download-ggml-model.sh base.en

# 轉錄
./main -m models/ggml-base.en.bin -f audio.wav -osrt

# 含時間戳記
./main -m models/ggml-base.en.bin -f audio.wav -ocsv

輸出格式

SRT(SubRip 字幕)

1
00:00:01,000 --> 00:00:04,500
您好,歡迎觀看本影片。

2
00:00:05,000 --> 00:00:08,200
今天我們將討論影片剪輯。

VTT(WebVTT)

WEBVTT

00:00:01.000 --> 00:00:04.500
您好,歡迎觀看本影片。

00:00:05.000 --> 00:00:08.200
今天我們將討論影片剪輯。

JSON(含逐字時間戳記)

{
  "text": "您好,歡迎觀看本影片。",
  "segments": [
    {
      "id": 0,
      "start": 1.0,
      "end": 4.5,
      "text": " 您好,歡迎觀看本影片。",
      "words": [
        {"word": "Hello", "start": 1.0, "end": 1.3},
        {"word": "and", "start": 1.4, "end": 1.5},
        {"word": "welcome", "start": 1.6, "end": 2.0},
        {"word": "to", "start": 2.1, "end": 2.2},
        {"word": "this", "start": 2.3, "end": 2.5},
        {"word": "video", "start": 2.6, "end": 3.0}
      ]
    }
  ]
}

轉錄前的音訊萃取

在轉錄影片前,先以最佳格式萃取出音訊:

# 萃取音訊為 WAV(16kHz, 單聲道 - Whisper 最佳格式)
ffmpeg -i video.mp4 -ar 16000 -ac 1 -c:a pcm_s16le audio.wav

# 萃取為高品質 WAV 以供歸檔
ffmpeg -i video.mp4 -vn -c:a pcm_s16le audio.wav

# 萃取為壓縮 MP3(較小,仍可使用)
ffmpeg -i video.mp4 -vn -c:a libmp3lame -q:a 2 audio.mp3

時間同步

將 Whisper JSON 轉換為 FCP 時間碼

import json

def whisper_to_fcp_timing(whisper_json_path, fps=24):
    """將 Whisper JSON 輸出轉換為與 Final Cut Pro 相容的時間碼。"""
    with open(whisper_json_path) as f:
        data = json.load(f)

    segments = []
    for seg in data.get("segments", []):
        segments.append({
            "start_time": seg["start"],
            "end_time": seg["end"],
            "start_frame": int(seg["start"] * fps),
            "end_frame": int(seg["end"] * fps),
            "text": seg["text"].strip(),
            "words": seg.get("words", [])
        })

    return segments

幀精確時間

# 取得精確幀數和持續時間
ffprobe -v error -count_frames -select_streams v:0 \
  -show_entries stream=nb_read_frames,duration,r_frame_rate \
  -of json video.mp4

說話者辨識

針對多人對話內容,請使用 pyannote.audio:

pip install pyannote.audio
from pyannote.audio import Pipeline

pipeline = Pipeline.from_pretrained("pyannote/[email protected]")
diarization = pipeline("audio.wav")

for turn, _, speaker in diarization.itertracks(yield_label=True):
    print(f"{turn.start:.1f}s - {turn.end:.1f}s: {speaker}")

批次處理

#!/bin/bash
# 轉錄目錄中的所有影片

MODEL="small"
OUTPUT_DIR="transcripts"
mkdir -p "$OUTPUT_DIR"

for video in *.mp4 *.mov *.avi; do
  [[ -f "$video" ]] || continue

  base="${video%.*}"

  # 萃取音訊
  ffmpeg -i "$video" -ar 16000 -ac 1 -c:a pcm_s16le "/tmp/${base}.wav" -y

  # 轉錄
  whisper "/tmp/${base}.wav" --model "$MODEL" \
    --output_format all \
    --output_dir "$OUTPUT_DIR"

  # 清理暫存音訊
  rm "/tmp/${base}.wav"

  echo "已轉錄:$video"
done

品質優化

提升準確度

  1. 轉錄前降噪:
ffmpeg -i noisy_audio.wav -af "highpass=f=200,lowpass=f=3000,afftdn=nf=-25" clean_audio.wav
  1. 使用語言提示:
whisper audio.mp3 --language en --model medium
  1. 提供初始提示以提供上下文:
whisper audio.mp3 --initial_prompt "有關影片剪輯軟體的技術討論。"

效能提示

  1. GPU 加速(若可用):
whisper audio.mp3 --model large-v3 --device cuda
  1. 針對長影片分段處理:
# 將音訊分割成 10 分鐘的片段
# 轉錄每個片段
# 合併結果並調整時間偏移

錯誤處理

# 在轉錄前驗證音訊檔案
validate_audio() {
  local file="$1"
  if ffprobe -v error -select_streams a:0 -show_entries stream=codec_type -of csv=p=0 "$file" 2>/dev/null | grep -q "audio"; then
    return 0
  else
    echo "錯誤:$file 中找不到音訊串流"
    return 1
  fi
}

# 檢查 Whisper 安裝
check_whisper() {
  if command -v whisper &> /dev/null; then
    echo "Whisper 可用"
    return 0
  else
    echo "錯誤:Whisper 未安裝。請執行:pip install openai-whisper"
    return 1
  fi
}

相關技能

  • ffmpeg-core - 音訊萃取與前處理
  • final-cut-pro - 將轉錄稿匯入為標題或標記

相關技能