openai/whisper
Robust Speech Recognition via Large-Scale Weak Supervision
Whisper – 开源语音转文本模型
功能简介 – Whisper 是一个基于 Transformer 的 sequence-to-sequence 模型,可以将音频转换为文本。它由 OpenAI 在大规模多语言音频数据集上训练而成,因此单个模型即可实现:
- 多种语言的语音转录,
- 将口语翻译成英语,
- 识别所说的语言,以及
- 执行语音活动检测 (VAD)。
重要意义 – Whisper 不是采用独立的组件流水线(VAD → 语言识别 → ASR → 翻译),而是在一次处理中完成所有工作,这简化了开发过程,并且在广泛的语言和音频条件下开箱即用效果良好。
模型大小
| 大小 | 参数量 | 仅限英语 | 多语言 | VRAM (约) | 相对速度* |
|---|---|---|---|---|---|
| tiny | 39 M | tiny.en |
tiny |
~1 GB | ~10× (对比 large) |
| base | 74 M | base.en |
base |
~1 GB | ~7× |
| small | 244 M | small.en |
small |
~2 GB | ~4× |
| medium | 769 M | medium.en |
medium |
~5 GB | ~2× |
| large | 1 550 M | – | large |
~10 GB | 1× |
| turbo | 809 M | – | turbo |
~6 GB | ~8× |
| *速度是在 A100 上转录英语时的测量值;实际速度随语言、硬件和音频而异。 |
提示: 仅限英语 (*.en) 模型在英语方面的准确度稍高,尤其是 tiny 和 base 版本。turbo 模型是 large-v3 的速度优化版本,在准确度上略有折衷。
快速入门 (CLI)
# 安装包和 ffmpeg (音频解码必需)
pip install -U openai-whisper
# 在 Ubuntu/Debian 上你还需要安装 ffmpeg:
sudo apt update && sudo apt install ffmpeg
# 转录一个或多个文件 (默认使用快速的 "turbo" 模型)
whisper audio.flac audio.mp3 audio.wav --model turbo
使用 --language <Lang> 来强制指定语言,或在多语言模型上使用 --task translate 来获取英语翻译。
在 Python 中使用 Whisper
import whisper
model = whisper.load_model("turbo") # 任何大小名称均可
result = model.transcribe("audio.mp3")
print(result["text"])
若需更底层的控制,你可以:
- 使用
whisper.load_audio/whisper.pad_or_trim加载并填充/裁剪音频。 - 使用
whisper.log_mel_spectrogram转换为 log-Mel 频谱图。 - 使用
model.detect_language(mel)检测语言。 - 使用
whisper.decode(model, mel, whisper.DecodingOptions())进行解码。
安装注意事项
- 需要 Python 3.8-3.11 和较新版本的 PyTorch。
- 该包依赖于 OpenAI 的快速分词器 tiktoken;在某些平台上,你可能需要 Rust 工具链 (
rustc,cargo) 和setuptools-rust来进行构建。 - 系统路径中必须可以使用
ffmpeg,以便用于 CLI 和 Python 中的音频加载。
许可证
代码和模型权重均根据 MIT License 发布。
更多学习资源
- 博客文章 – https://openai.com/blog/whisper
- 论文 – https://arxiv.org/abs/2212.04356
- 模型卡 – https://github.com/openai/whisper/blob/main/model-card.md
- Colab 演示 – https://colab.research.google.com/github/openai/whisper/blob/master/notebooks/LibriSpeech.ipynb
- 社区示例 – 请参阅仓库中的 Show and tell 讨论类别。
相关
- Dispatch
- 项目
- 项目
- 项目
- Dispatch