Faster Whisper 是做什么的?
基于 faster-whisper 的本地语音转文字工具——这是 OpenAI Whisper 的 CTranslate2 重实现,运行速度快 4-6 倍,精度相同。通过 GPU 加速,可实现约 20 倍实时转录(一个 10 分钟的音频文件约 30 秒)。
何时使用
在以下场景使用此技能:
- 转录音/视频文件——会议、访谈、播客、讲座、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 3.12,通过 winget 自动安装
- 如果找不到 ffmpeg,通过 winget 自动安装
- 检测 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 上安装 WSL 版 NVIDIA CUDA 驱动程序
使用方法
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 束搜索大小(默认:5,越大越精确但也越慢)
--vad 启用语音活动检测(去除静音)
--json, -j 输出为 JSON
--output, -o 将转录保存到文件
--device cpu 或 cuda(自动检测)
--compute-type int8, float16, float32(默认:自动优化)
--quiet, -q 压制进度消息
示例
# 转录音频(用 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
# 高精度转录,使用更大的束搜索大小
./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 |
| 过度优化束搜索大小 | 超过 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
找不到 nvidia-smi 但有 GPU:安装 NVIDIA 驱动程序——Game Ready 或 Studio 驱动程序包含 nvidia-smi