语音转文字工具 Whisper 的安装与使用。
1、ffmpeg 安装
系统环境
| 类型 | 配置 |
|---|---|
| CPU | Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz |
| GPU | NVIDIA GeForce RTX 4060 Ti 8G |
| RAM | 32G |
| System | Windows 10 专业版 22H2 |
ffmpeg 下载:Linux 版本、Windows 版本
Windows 下解压到本地并配置到环境变量 PATH 中:D:\Program Files\ffmpeg\bin

验证安装:ffmpeg -version
2、pytorch 安装
项目地址:https://github.com/openai/whisper,官方说明使用的是 Python 3.9.9 进行测试的。
下载 Python 3.9.9:https://www.python.org/downloads/release/python-399/,安装时勾选添加到 PATH
# 配置国内源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pytorch 官网地址:https://pytorch.org/,根据环境执行相应安装命令,GPU 版本需要先将显卡驱动到最新版本
# 查看允许安装的 CUDA 版本号,本机最高支持 13.0 版本
nvidia-smi
# 创建虚拟环境
python -m venv .venv
# 激活虚拟环境
.venv\Scripts\activate
# CPU 版本
pip install torch torchvision torchaudio
# GPU 版本
pip install torch torchvision torchaudio --index-url https://mirrors.nju.edu.cn/pytorch/whl/cu129

3、whisper 安装使用
# 拉取最新代码并安装依赖
pip install git+https://github.com/openai/whisper.git
# 后续项目代码有更新时执行
pip install --upgrade --no-deps --force-reinstall git+https://github.com/openai/whisper.git
# 转录音频文件,首次执行时会自动下载模型,存放位置:%USERPROFILE%\.cache\whisper
whisper test.mp3
# 指定音频的语言(加速识别)
whisper test.mp3 --language Chinese
# 指定模型
whisper test.mp3 --model medium
Whisper 提供 5 种规模的模型,按需选择:
| 模型 | 参数量 | 显存占用 | 相对速度 | 英文 WER | 多语言 WER |
|---|---|---|---|---|---|
| tiny | 39M | ~1GB | ~32x | 5.0% | 12.1% |
| base | 74M | ~1GB | ~16x | 3.4% | 8.4% |
| small | 244M | ~2GB | ~6x | 2.3% | 5.4% |
| medium | 769M | ~5GB | ~2x | 1.7% | 3.8% |
| large/large-v3 | 1550M | ~10GB | 1x | 1.4% | 3.0% |
4、其它
执行命令后报错:
E:\Git\whisper-demo\.venv\lib\site-packages\whisper\transcribe.py:132: UserWarning: FP16 is not supported on CPU; using FP32 instead
warnings.warn("FP16 is not supported on CPU; using FP32 instead")
这是由于电脑上安装的 PyTorch 版本不支持 GPU,所以 Whisper 只能跑在 CPU 上,可以尝试安装 GPU 旧版本
# 卸载现有依赖
pip uninstall torch torchvision
# 虚拟环境中输出是 True 和显卡型号,就说明 GPU 版 PyTorch 安装成功
python -c "import torch; print(torch.cuda.is_available());print(torch.cuda.get_device_name(0))"
- 本文作者:Nine
- 本文链接:https://blog.nine.gt.tc/2025/11/24/whisper-with-install/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)