mcpField
W
whisper

whisper

github.com/ovachiever创意与媒体5666 次安装48 周前更新
代码仓库

关于 whisper

whisper 是 OpenAI 的多语言语音识别模型,可用于音频转写和翻译。它支持 99 种语言、多种模型规格,并提供 Python 与命令行用法。

主要功能

  1. 01支持 99 种语言的语音转写
  2. 02将音频翻译成英语
  3. 03可选择多种模型规格
  4. 04提供词级时间戳
  5. 05支持 Python 和命令行

适用场景

  1. 01转写播客和视频
  2. 02自动生成会议记录
  3. 03处理嘈杂的多语言音频

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/ovachiever/droid-tings --skill whisper

安装后在 Claude Code 中输入/whisper确认已加载。

附带文件references/languages.md

详细介绍

Whisper - 强健的语音识别

OpenAI 的多语言语音识别模型。

何时使用 Whisper

适用场景:

  • 语音转文字转录(99 种语言)
  • 播客/视频转录
  • 自动生成会议纪要
  • 翻译成英语
  • 嘈杂音频转录
  • 多语言音频处理

指标:

  • 72,900+ GitHub 星标
  • 支持 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
tiny39M✓✓~32x~1 GB
base74M✓✓~16x~1 GB
small244M✓✓~6x~2 GB
medium769M✓✓~2x~5 GB
large1550M✗✓1x~10 GB
turbo809M✗✓~8x~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. 实时延迟 - 不适合实时字幕

资源

评论

支持 Markdown