Whisper 速查表
Whisper 是 OpenAI 开源的通用语音识别模型。支持 100+ 语言的转录和翻译,提供 tiny/base/small/medium/large 多个模型尺寸,可在 CPU 或 GPU 上运行。支持 txt/vtt/srt/tsv/json 多种输出格式。
快速开始
``bash
# 安装
pip install openai-whisper
# 基本转录 whisper recording.mp3
# 指定模型和语言 whisper meeting.mp3 --model small --language zh
# 中文音频翻译为英文 whisper chinese_speech.mp3 --task translate
# 生成 SRT 字幕 whisper video_audio.mp3 --model base --output_format srt --output_dir ./subtitles
# GPU 加速转录
whisper long_podcast.mp3 --model medium --device cuda --fp16 True
`
模型尺寸
五个预训练模型:tiny(39M 参数,~1GB 显存)、base(74M)、small(244M,~2GB)、medium(769M,~5GB)、large(1.5B,~10GB)。首次使用自动下载。
转录与翻译
两种任务模式:transcribe(原语言转文字)和 translate(转英文)。用 --language 指定源语言提高准确率。双语音频自动检测。
输出格式
txt(纯文本,默认)、vtt(WebVTT 字幕)、srt(SubRip 字幕)、tsv(带时间戳的表格)、json(完整元数据,含片段和逐词时间戳)。用 all 一次性生成所有格式。
高级选项
--initial_prompt 引导风格或领域术语。--temperature 控制采样随机性(0 = 确定性)。--condition_on_previous_text` 改善长音频连贯性。Shell 通配符批量转录多个文件。
启动模式(20)
| 命令 | 难度 | ||
|---|---|---|---|
whisper --help显示 Whisper CLI 帮助 | 基础 | whisper --help | |
whisper audio.mp3转录音频文件为文字(基本用法) | 基础 | whisper recording.mp3 | |
whisper audio.mp3 --model指定 Whisper 模型大小 | 基础 | whisper recording.mp3 --model medium | |
whisper audio.mp3 --model tiny使用最小模型(最快,最不准确) | 基础 | whisper recording.mp3 --model tiny | |
whisper audio.mp3 --model large使用最大模型(最慢,最准确) | 基础 | whisper recording.mp3 --model large | |
whisper audio.mp3 --language指定音频语言(提高准确率) | 中级 | whisper chinese_speech.mp3 --language zh | |
whisper audio.mp3 --task transcribe转录任务(默认,保持原语言) | 基础 | whisper french_audio.mp3 --task transcribe | |
whisper audio.mp3 --task translate翻译任务(将任何语言翻译为英文) | 基础 | whisper japanese_audio.mp3 --task translate | |
whisper audio.mp3 --output_format指定输出格式(txt/vtt/srt/tsv/json/all) | 中级 | whisper recording.mp3 --output_format srt | |
whisper audio.mp3 --output_dir指定输出目录 | 基础 | whisper recording.mp3 --output_dir ./transcripts | |
whisper audio.mp3 --device指定推理设备(cpu/cuda) | 中级 | whisper recording.mp3 --device cuda | |
whisper audio.mp3 --fp16启用半精度推理(GPU 加速) | 中级 | whisper recording.mp3 --fp16 True | |
whisper audio.mp3 --verbose显示详细输出(含时间戳和置信度) | 基础 | whisper recording.mp3 --verbose True | |
whisper audio.mp3 --temperature设置采样温度(0-1,默认 0) | 中级 | whisper recording.mp3 --temperature 0.2 | |
whisper audio.mp3 --initial_prompt设置初始提示词(引导风格或纠正术语) | 高级 | whisper medical.mp3 --initial_prompt 'Use medical terminology.' | |
whisper audio.mp3 --condition_on_previous_text利用前文提高连贯性 | 中级 | whisper long_lecture.mp3 --condition_on_previous_text True | |
pip install openai-whisper安装 Whisper | 基础 | pip install openai-whisper | |
pip install openai-whisper[audio]安装 Whisper(含音频依赖) | 基础 | pip install openai-whisper[audio] | |
whisper --model small audio.mp3使用 small 模型转录(速度与质量的平衡) | 基础 | whisper --model small meeting.mp3 --output_dir ./notes --output_format txt | |
whisper dir/*.mp3批量转录目录下所有音频文件 | 中级 | whisper podcasts/*.mp3 --model base --output_dir ./transcripts |