跳到主要内容

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. 实时延迟 - 不适合实时字幕生成

资源