1. 安装 Whisper
1.1 系统依赖
- 必须安装 FFmpeg:处理音频/视频编解码。
- Windows: 安装后需将
ffmpeg添加到系统环境变量PATH。
- Windows: 安装后需将
推荐通过 官方二进制包 安装,或使用 Chocolatey:
choco install ffmpeg
macOS:
# 使用 Homebrew
brew install ffmpeg
Linux:
# Debian/Ubuntu
sudo apt update && sudo apt install ffmpeg
# CentOS/RHEL
sudo yum install ffmpeg ffmpeg-devel
1.2 安装 Whisper
- Python 版本要求:建议 Python 3.9 或更高版本。
- 依赖项:自动安装
torch,numpy,tqdm,more_itertools等。
验证安装:
whisper --version
# 输出 Whisper 版本
通过 pip 安装:
pip install -U openai-whisper
1.3 GPU 加速(可选)
- NVIDIA GPU 用户:
- 安装 CUDA Toolkit 11.7+ 和 cuDNN。
- Apple Silicon (M1/M2) 用户:
运行命令时添加 --device mps:
whisper audio.mp3 --device mps
使用 Metal Performance Shaders (MPS) 加速:
pip install torch torchaudio -U --pre --extra-index-url https://download.pytorch.org/whl/nightly/cpu
验证 GPU 是否启用:
import torch
print(torch.cuda.is_available())
# 输出应为 True

