语音转文字工具 Whisper 的安装与使用

2025/11/24 更新 2 次 更新于 2026/08/12 Net 共 1660 字,约 5 分钟

语音转文字工具 Whisper 的安装与使用。

1、ffmpeg 安装

系统环境

类型配置
CPUIntel(R) Core(TM) i7-9700K CPU @ 3.60GHz
GPUNVIDIA GeForce RTX 4060 Ti 8G
RAM32G
SystemWindows 10 专业版 22H2

ffmpeg 下载:Linux 版本Windows 版本

Windows 下解压到本地并配置到环境变量 PATH 中:D:\Program Files\ffmpeg\bin

image-20251124161450858

验证安装: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

image-20251124162911699

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
tiny39M~1GB~32x5.0%12.1%
base74M~1GB~16x3.4%8.4%
small244M~2GB~6x2.3%5.4%
medium769M~5GB~2x1.7%3.8%
large/large-v31550M~10GB1x1.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))"

Search

    Table of Contents