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
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"])

若需更底層的控制,你可以:

  1. 使用 whisper.load_audio / whisper.pad_or_trim 載入並填充/裁剪音訊。
  2. 使用 whisper.log_mel_spectrogram 轉換為 log-Mel 頻譜圖。
  3. 使用 model.detect_language(mel) 檢測語言。
  4. 使用 whisper.decode(model, mel, whisper.DecodingOptions()) 進行解碼。

安裝注意事項

  • 需要 Python 3.8-3.11 和較新版本的 PyTorch。
  • 該套件依賴於 OpenAI 的快速分詞器 tiktoken;在某些平台上,你可能需要 Rust 工具鏈 (rustc, cargo) 和 setuptools-rust 來進行建置。
  • 系統路徑中必須可以使用 ffmpeg,以便用於 CLI 和 Python 中的音訊載入。

授權

程式碼和模型權重均根據 MIT License 發布。


更多學習資源

相關

  • Dispatch
  • 專案
  • 專案
  • 專案
  • Dispatch