跳到主要內容

Whisper

OpenAI 的通用語音識別模型。支持 99 種語言、轉錄、翻譯成英語以及語言識別。提供從 tiny(3900 萬參數)到 large(15.5 億參數)的六種模型尺寸。適用於語音轉文本、播客轉錄或多語言音頻處理。最適合用於穩健的多語言自動語音識別 (ASR)。

技能元數據

來源可選 — 使用 hermes skills install official/mlops/whisper 安裝
路徑optional-skills/mlops/whisper
版本1.0.0
作者Orchestra Research
許可證MIT
依賴項openai-whisper, transformers, torch
標籤Whisper, Speech Recognition, ASR, Multimodal, Multilingual, OpenAI, Speech-To-Text, Transcription, Translation, Audio Processing

參考:完整 SKILL.md

信息

以下是 Hermes 在觸發此技能時加載的完整技能定義。這是技能激活時代理看到的指令。

Whisper - 穩健的語音識別

OpenAI 的多語言語音識別模型。

何時使用 Whisper

使用時機:

  • 語音轉文本轉錄(支持 99 種語言)
  • 播客/視頻轉錄
  • 會議紀要自動化
  • 翻譯成英語
  • 嘈雜音頻轉錄
  • 多語言音頻處理

指標

  • GitHub 星標超過 72,900+
  • 支持 99 種語言
  • 基於 680,000 小時音頻訓練
  • MIT 許可證

改用替代方案

  • AssemblyAI:託管 API,說話人分離
  • Deepgram:實時流式 ASR
  • Google Speech-to-Text:基於雲的服務

快速開始

安裝

# Requires Python 3.8-3.11
pip install -U openai-whisper

# Requires ffmpeg
# macOS: brew install ffmpeg
# Ubuntu: sudo apt install ffmpeg
# Windows: choco install ffmpeg

基本轉錄

import whisper

# Load model
model = whisper.load_model("base")

# Transcribe
result = model.transcribe("audio.mp3")

# Print text
print(result["text"])

# Access segments
for segment in result["segments"]:
print(f"[{segment['start']:.2f}s - {segment['end']:.2f}s] {segment['text']}")

模型尺寸

# Available models
models = ["tiny", "base", "small", "medium", "large", "turbo"]

# Load specific model
model = whisper.load_model("turbo") # Fastest, good quality
模型參數量僅英語多語言速度顯存 (VRAM)
tiny3900 萬~32 倍~1 GB
base7400 萬~16 倍~1 GB
small2.44 億~6 倍~2 GB
medium7.69 億~2 倍~5 GB
large15.5 億1 倍~10 GB
turbo8.09 億~8 倍~6 GB

建議:使用 turbo 以獲得最佳速度/質量平衡,使用 base 進行原型開發

轉錄選項

語言指定

# Auto-detect language
result = model.transcribe("audio.mp3")

# Specify language (faster)
result = model.transcribe("audio.mp3", language="en")

# Supported: en, es, fr, de, it, pt, ru, ja, ko, zh, and 89 more

任務選擇

# Transcription (default)
result = model.transcribe("audio.mp3", task="transcribe")

# Translation to English
result = model.transcribe("spanish.mp3", task="translate")
# Input: Spanish audio → Output: English text

初始提示詞

# Improve accuracy with context
result = model.transcribe(
"audio.mp3",
initial_prompt="This is a technical podcast about machine learning and AI."
)

# Helps with:
# - Technical terms
# - Proper nouns
# - Domain-specific vocabulary

時間戳

# Word-level timestamps
result = model.transcribe("audio.mp3", word_timestamps=True)

for segment in result["segments"]:
for word in segment["words"]:
print(f"{word['word']} ({word['start']:.2f}s - {word['end']:.2f}s)")

溫度回退

# Retry with different temperatures if confidence low
result = model.transcribe(
"audio.mp3",
temperature=(0.0, 0.2, 0.4, 0.6, 0.8, 1.0)
)

命令行用法

# Basic transcription
whisper audio.mp3

# Specify model
whisper audio.mp3 --model turbo

# Output formats
whisper audio.mp3 --output_format txt # Plain text
whisper audio.mp3 --output_format srt # Subtitles
whisper audio.mp3 --output_format vtt # WebVTT
whisper audio.mp3 --output_format json # JSON with timestamps

# Language
whisper audio.mp3 --language Spanish

# Translation
whisper spanish.mp3 --task translate

批量處理

import os

audio_files = ["file1.mp3", "file2.mp3", "file3.mp3"]

for audio_file in audio_files:
print(f"Transcribing {audio_file}...")
result = model.transcribe(audio_file)

# Save to file
output_file = audio_file.replace(".mp3", ".txt")
with open(output_file, "w") as f:
f.write(result["text"])

實時轉錄

# For streaming audio, use faster-whisper
# pip install faster-whisper

from faster_whisper import WhisperModel

model = WhisperModel("base", device="cuda", compute_type="float16")

# Transcribe with streaming
segments, info = model.transcribe("audio.mp3", beam_size=5)

for segment in segments:
print(f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}")

GPU 加速

import whisper

# Automatically uses GPU if available
model = whisper.load_model("turbo")

# Force CPU
model = whisper.load_model("turbo", device="cpu")

# Force GPU
model = whisper.load_model("turbo", device="cuda")

# 10-20× faster on GPU

與其他工具集成

字幕生成

# Generate SRT subtitles
whisper video.mp4 --output_format srt --language English

# Output: video.srt

與 LangChain 結合

from langchain.document_loaders import WhisperTranscriptionLoader

loader = WhisperTranscriptionLoader(file_path="audio.mp3")
docs = loader.load()

# Use transcription in RAG
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings

vectorstore = Chroma.from_documents(docs, OpenAIEmbeddings())

從視頻中提取音頻

# Use ffmpeg to extract audio
ffmpeg -i video.mp4 -vn -acodec pcm_s16le audio.wav

# Then transcribe
whisper audio.wav

最佳實踐

  1. 使用 turbo 模型 - 英語場景下最佳的速度/質量平衡
  2. 指定語言 - 比自動檢測更快
  3. 添加初始提示詞 - 改善專業術語識別
  4. 使用 GPU - 速度快 10-20 倍
  5. 批量處理 - 效率更高
  6. 轉換為 WAV - 兼容性更好
  7. 分割長音頻 - 切成 <30 分鐘的片段
  8. 檢查語言支持 - 不同語言的質量有所差異
  9. 使用 faster-whisper - 比 openai-whisper 快 4 倍
  10. 監控顯存 (VRAM) - 根據硬件調整模型尺寸

性能

模型實時因子 (CPU)實時因子 (GPU)
tiny~0.32~0.01
base~0.16~0.01
turbo~0.08~0.01
large~1.0~0.05

實時因子:0.1 = 比實時速度快 10 倍

語言支持

支持最好的語言:

  • 英語 (en)
  • 西班牙語 (es)
  • 法語 (fr)
  • 德語 (de)
  • 意大利語 (it)
  • 葡萄牙語 (pt)
  • 俄語 (ru)
  • 日語 (ja)
  • 韓語 (ko)
  • 中文 (zh)

完整列表:共 99 種語言

侷限性

  1. 幻覺 - 可能會重複或編造文本
  2. 長形式準確性 - 超過 30 分鐘的音頻準確率下降
  3. 說話人識別 - 不支持說話人分離
  4. 口音 - 質量因口音而異
  5. 背景噪音 - 可能影響準確性
  6. 實時延遲 - 不適合實時字幕生成

資源