Faster Whisper 是做什麼的?
使用 faster-whisper 進行本地語音轉文字 — 這是 OpenAI Whisper 基於 CTranslate2 的重新實作,運行速度快 4-6 倍,且準確率相同。使用 GPU 加速時,可達到約 20 倍即時轉錄(10 分鐘的音訊檔案約 30 秒完成)。
使用時機
當您需要以下功能時,可使用此技能:
- 轉錄音訊/視訊檔案 — 會議、訪談、Podcast、講座、YouTube 影片
- 將語音本地轉換為文字 — 無 API 費用,可離線運作(下載模型後)
- 批次處理多個音訊檔案 — 對大量收藏集有效
- 生成字幕/標題 — 提供逐字時間戳
- 多語言轉錄 — 支援 99 種以上語言,具自動偵測功能
觸發詞:「轉錄此音訊」、「將語音轉為文字」、「他們說了什麼」、「製作文字稿」、「音訊轉文字」、「為此影片加字幕」
何時不應使用:
- 即時/串流轉錄(請改用串流最佳化工具)
- 僅有雲端環境且無本地運算資源
- 音訊檔案小於 10 秒,此時 API 呼叫延遲影響不大
快速參考
| 任務 | 指令 | 備註 |
|---|---|---|
| 基本轉錄 | ./scripts/transcribe audio.mp3 | 使用預設的 distil-large-v3 |
| 更快的英文轉錄 | ./scripts/transcribe audio.mp3 --model distil-medium.en --language en | 僅英文,快 6.8 倍 |
| 最高準確度 | ./scripts/transcribe audio.mp3 --model large-v3-turbo --beam-size 10 | 較慢但品質最佳 |
| 逐字時間戳 | ./scripts/transcribe audio.mp3 --word-timestamps | 用於字幕/標題 |
| JSON 輸出 | ./scripts/transcribe audio.mp3 --json -o output.json | 程式化存取 |
| 多語言轉錄 | ./scripts/transcribe audio.mp3 --model large-v3-turbo | 自動偵測語言 |
| 移除靜音 | ./scripts/transcribe audio.mp3 --vad | 語音活動偵測 |
模型選擇
根據您的需求選擇合適的模型:
digraph model_selection {
rankdir=LR;
node [shape=box, style=rounded];
start [label="開始", shape=doublecircle];
need_accuracy [label="需要最高
準確度?", shape=diamond];
multilingual [label="多語言
內容?", shape=diamond];
resource_constrained [label="資源
有限?", shape=diamond];
large_v3 [label="large-v3
或
large-v3-turbo", style="rounded,filled", fillcolor=lightblue];
large_turbo [label="large-v3-turbo", style="rounded,filled", fillcolor=lightblue];
distil_large [label="distil-large-v3
(預設)", style="rounded,filled", fillcolor=lightgreen];
distil_medium [label="distil-medium.en", style="rounded,filled", fillcolor=lightyellow];
distil_small [label="distil-small.en", style="rounded,filled", fillcolor=lightyellow];
start -> need_accuracy;
need_accuracy -> large_v3 [label="是"];
need_accuracy -> multilingual [label="否"];
multilingual -> large_turbo [label="是"];
multilingual -> resource_constrained [label="否 (英文)"];
resource_constrained -> distil_small [label="行動/邊緣裝置"];
resource_constrained -> distil_medium [label="有些限制"];
resource_constrained -> distil_large [label="無限制"];
}
模型表格
標準模型(完整 Whisper)
| 模型 | 大小 | 速度 | 準確度 | 使用案例 |
|---|---|---|---|---|
tiny / tiny.en | 39M | 最快 | 基本 | 快速草稿 |
base / base.en | 74M | 非常快 | 良好 | 一般用途 |
small / small.en | 244M | 快 | 較好 | 大多數任務 |
medium / medium.en | 769M | 中等 | 高 | 高品質轉錄 |
large-v1/v2/v3 | 1.5GB | 較慢 | 最佳 | 最高準確度 |
large-v3-turbo | 809M | 快 | 極佳 | 推薦用於準確度 |
蒸餾模型(約快 6 倍,WER 差約 1%)
| 模型 | 大小 | 與標準模型速度比 | 準確度 | 使用案例 |
|---|---|---|---|---|
distil-large-v3 | 756M | 約快 6.3 倍 | 9.7% WER | 預設,最佳平衡 |
distil-large-v2 | 756M | 約快 5.8 倍 | 10.1% WER | 備用方案 |
distil-medium.en | 394M | 約快 6.8 倍 | 11.1% WER | 僅限英文,資源有限 |
distil-small.en | 166M | 約快 5.6 倍 | 12.1% WER | 行動/邊緣裝置 |
.en 模型僅限英文,對於英文內容速度稍快且效果更佳。
設定
Linux / macOS / WSL2
# 執行設定腳本(建立 venv、安裝依賴、自動偵測 GPU)
./setup.sh
Windows(原生)
# 從 PowerShell 執行(若缺少則透過 winget 自動安裝 Python 與 ffmpeg)
.\setup.ps1
Windows 設定腳本將:
- 若未找到 Python,透過 winget 自動安裝 Python 3.12
- 若未找到 ffmpeg,透過 winget 自動安裝 ffmpeg
- 偵測 NVIDIA GPU 並安裝支援 CUDA 的 PyTorch
- 建立 venv 並安裝所有依賴
系統需求:
- Linux/macOS/WSL2:Python 3.10+、ffmpeg
- Windows:無需事先安裝!設定腳本會透過 winget 自動安裝必要元件
平台支援
| 平台 | 加速 | 速度 | 自動安裝 |
|---|---|---|---|
| Windows + NVIDIA GPU | CUDA | 約 20 倍即時 🚀 | ✅ 完整 |
| Linux + NVIDIA GPU | CUDA | 約 20 倍即時 🚀 | 手動安裝必要元件 |
| WSL2 + NVIDIA GPU | CUDA | 約 20 倍即時 🚀 | 手動安裝必要元件 |
| macOS Apple Silicon | CPU* | 約 3-5 倍即時 | 手動安裝必要元件 |
| macOS Intel | CPU | 約 1-2 倍即時 | 手動安裝必要元件 |
| Windows(無 GPU) | CPU | 約 1 倍即時 | ✅ 完整 |
| Linux(無 GPU) | CPU | 約 1 倍即時 | 手動安裝必要元件 |
*faster-whisper 在 macOS 上僅使用 CTranslate2 的 CPU 模式,但 Apple Silicon 的效能已足夠實際使用。
GPU 支援(重要!)
設定腳本會自動偵測您的 GPU 並安裝支援 CUDA 的 PyTorch。請務必在可用時使用 GPU — CPU 轉錄極慢。
| 硬體 | 速度 | 9 分鐘影片 |
|---|---|---|
| RTX 3070(GPU) | 約 20 倍即時 | 約 27 秒 |
| CPU(int8) | 約 0.3 倍即時 | 約 30 分鐘 |
若設定腳本未偵測到您的 GPU,請手動安裝支援 CUDA 的 PyTorch:
Linux/macOS/WSL2:
# 針對 CUDA 12.x
uv pip install --python .venv/bin/python torch --index-url https://download.pytorch.org/whl/cu121
# 針對 CUDA 11.x
uv pip install --python .venv/bin/python torch --index-url https://download.pytorch.org/whl/cu118
Windows:
# 針對 CUDA 12.x
.venv\Scripts\pip install torch --index-url https://download.pytorch.org/whl/cu121
# 針對 CUDA 11.x
.venv\Scripts\pip install torch --index-url https://download.pytorch.org/whl/cu118
- Windows 使用者:請確保已安裝 NVIDIA 驅動程式
- WSL2 使用者:請確保已在 Windows 上安裝 NVIDIA CUDA 驅動程式 for WSL
使用方法
Linux/macOS/WSL2:
# 基本轉錄
./scripts/transcribe audio.mp3
# 使用特定模型
./scripts/transcribe audio.wav --model large-v3-turbo
# 使用逐字時間戳
./scripts/transcribe audio.mp3 --word-timestamps
# 指定語言(比自動偵測更快)
./scripts/transcribe audio.mp3 --language en
# JSON 輸出
./scripts/transcribe audio.mp3 --json
Windows(cmd 或 PowerShell):
# 基本轉錄
.\scripts\transcribe.cmd audio.mp3
# 使用特定模型
.\scripts\transcribe.cmd audio.wav --model large-v3-turbo
# 使用逐字時間戳(PowerShell 原生語法亦可)
.\scripts\transcribe.ps1 audio.mp3 -WordTimestamps
# JSON 輸出
.\scripts\transcribe.cmd audio.mp3 --json
選項
--model, -m 模型名稱(預設:distil-large-v3)
--language, -l 語言代碼(例如 en、es、fr — 省略則自動偵測)
--word-timestamps 包含逐字時間戳
--beam-size Beam search 大小(預設:5,越大越準確但越慢)
--vad 啟用語音活動偵測(移除靜音)
--json, -j 輸出為 JSON
--output, -o 將文字稿儲存至檔案
--device cpu 或 cuda(自動偵測)
--compute-type int8、float16、float32(預設:自動最佳化)
--quiet, -q 隱藏進度訊息
範例
# 轉錄 YouTube 音訊(先使用 yt-dlp 提取)
yt-dlp -x --audio-format mp3 <URL> -o audio.mp3
./scripts/transcribe audio.mp3
# 批次轉錄並輸出 JSON
for file in *.mp3; do
./scripts/transcribe "$file" --json > "${file%.mp3}.json"
done
# 使用較大 beam size 進行高準確度轉錄
./scripts/transcribe audio.mp3 \
--model large-v3-turbo --beam-size 10 --word-timestamps
# 快速英文轉錄
./scripts/transcribe audio.mp3 \
--model distil-medium.en --language en
# 使用 VAD 轉錄(移除靜音)
./scripts/transcribe audio.mp3 --vad
常見錯誤
| 錯誤 | 問題 | 解決方案 |
|---|---|---|
| GPU 可用時仍用 CPU | 轉錄慢 10-20 倍 | 在 Windows/Linux 上檢查 nvidia-smi;驗證 CUDA 安裝 |
| 未指定語言 | 對已知內容浪費時間自動偵測 | 當您知道語言時使用 --language en |
| 使用錯誤的模型 | 不必要地緩慢或準確度差 | 預設的 distil-large-v3 已足夠;僅在準確度問題時使用 large-v3 |
| 忽略蒸餾模型 | 錯過 6 倍加速且準確度損失小於 1% | 在嘗試標準模型前先試用 distil-large-v3 |
| 忘記安裝 ffmpeg | 設定失敗或無法處理音訊 | 設定腳本會處理此問題;手動安裝需另外安裝 ffmpeg |
| 記憶體不足錯誤 | 模型對可用 VRAM/RAM 而言過大 | 使用較小模型或 --compute-type int8 |
| 過度調整 beam size | 超過 beam-size 5-7 後效益遞減 | 預設 5 已足夠;關鍵文字稿可嘗試 10 |
效能說明
- 首次執行:將模型下載至
~/.cache/huggingface/(一次性) - GPU:若可用則自動使用 CUDA(快約 10-20 倍)
- 量化:在 CPU 上使用 INT8 以獲得約 4 倍加速,準確度損失極小
- 記憶體:
distil-large-v3:約 2GB RAM / 約 1GB VRAMlarge-v3-turbo:約 4GB RAM / 約 2GB VRAMtiny/base:<1GB RAM
為何選擇 faster-whisper?
- 速度:比 OpenAI 原始 Whisper 快約 4-6 倍
- 準確度:相同(使用相同模型權重)
- 效率:透過量化降低記憶體使用量
- 適合生產環境:穩定的 C++ 後端(CTranslate2)
- 蒸餾模型:約快 6 倍,準確度損失小於 1%
故障排除
「CUDA 不可用 — 使用 CPU」:安裝支援 CUDA 的 PyTorch(請參閱上方的 GPU 支援)
設定失敗:請確保已安裝 Python 3.10+
記憶體不足:使用較小模型或 --compute-type int8
CPU 上緩慢:此為預期情況 — 實際轉錄請使用 GPU
模型下載失敗:檢查 ~/.cache/huggingface/ 的權限(Linux/macOS)或 %USERPROFILE%\.cache\huggingface\(Windows)
Windows 專屬問題
「找不到 winget」:從 Microsoft Store 安裝 App Installer,或手動安裝 Python 與 ffmpeg
「安裝後 Python 不在 PATH 中」:關閉並重新開啟終端機,然後再次執行 setup.ps1
PowerShell 執行原則錯誤:執行 Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned,或改用 transcribe.cmd
雖有 GPU 但找不到 nvidia-smi:安裝 NVIDIA 驅動程式 — Game Ready 或 Studio 驅動程式均包含 nvidia-smi