你是否正被这些问题困扰?2小时会议录音,手动转录耗时又费力想给视频加字幕,付费制作性价比太低播客音频想转文字,逐句整理超费精力记者采访/用户访谈,大量录音整理压力大隐私敏感音频,不敢上传云端怕数据泄露openai-whisper——本地语音转文字神器,一站式解决所有难题!
什么是 openai-whisper?
OpenAI Whisper 是 OpenAI 开源的自动语音识别(ASR)模型 ,特点是:
| 特性 | 说明 |
|---|---|
| 无需 API Key,无需付费 | |
| 数据不出本地,隐私安全 | |
| 支持 99 种语言,包括中文方言 | |
| 下载模型后,无需联网也能用 | |
| 接近人类水平的识别准确率 |
安装方法
方法一:使用 Homebrew(macOS 推荐)
brew install openai-whisper
方法二:使用 pip(Python 环境)
pip install openai-whisper
方法三:通过 OpenClaw Skill 安装
skillhub install openai-whisper
验证安装
whisper --help
快速上手
最简单的用法
whisper audio.mp3
这会在当前目录生成:
-
•
audio.txt— 纯文本转录 -
•
audio.srt— SRT 字幕文件 -
•
audio.vtt— VTT 字幕文件 -
•
audio.json— JSON 格式(带时间戳)
指定输出格式
# 只要纯文本whisper audio.mp3 --output_format txt# 只要字幕文件whisper audio.mp3 --output_format srt# 输出到指定目录whisper audio.mp3 --output_dir ./transcripts
模型选择
Whisper 提供多种模型,按大小和准确率排序:
| 模型 | 参数量 | 显存需求 | 速度 | 准确率 |
|---|---|---|---|---|
tiny |
39M | ~1GB | ||
base |
74M | ~1GB | ||
small |
244M | ~2GB | ||
medium |
769M | ~5GB | ||
large |
1550M | ~10GB | ||
turbo |
809M | ~6GB |
推荐:
-
• 日常使用:
turbo(速度与准确率平衡) -
• 快速转录:
base或small -
• 最高准确率:
large
# 使用 turbo 模型(默认)whisper audio.mp3 --model turbo# 使用 small 模型(更快)whisper audio.mp3 --model small# 使用 large 模型(最准确)whisper audio.mp3 --model large
支持的音频格式
Whisper 支持几乎所有常见音频/视频格式:
| 类型 | 格式 |
|---|---|
| MP3, WAV, M4A, OGG, FLAC, AAC, OPUS | |
| MP4, MKV, AVI, MOV, WEBM | |
| iPhone .m4a, Android .ogg, 微信语音 |
实用参数详解
–language:指定语言
# 指定中文(提升准确率和速度)whisper audio.mp3 --language Chinese# 指定英文whisper audio.mp3 --language English# 指定日语whisper audio.mp3 --language Japanese
支持的语言: Chinese, English, Japanese, Korean, French, German, Spanish, Russian, Arabic 等 99 种语言。
–task:转录或翻译
# 转录(语音 → 文字,保持原语言)whisper audio.mp3 --task transcribe# 翻译(语音 → 英文文字)whisper audio.mp3 --task translate
–output_format:输出格式
| 格式 | 说明 | 用途 |
|---|---|---|
txt |
纯文本 | 阅读、编辑 |
srt |
SRT 字幕 | 视频字幕 |
vtt |
VTT 字幕 | 网页视频 |
json |
JSON 格式 | 程序处理 |
tsv |
TSV 格式 | 数据分析 |
–initial_prompt:初始提示
# 提供专业术语,提升准确率whisper audio.mp3 --initial_prompt "以下是技术会议录音,涉及人工智能、机器学习、深度学习等内容"
–temperature:采样温度
# 更确定性的输出(适合正式内容)whisper audio.mp3 --temperature 0# 更多样性的输出(适合创意内容)whisper audio.mp3 --temperature 0.5
实际应用场景
场景 1:会议录音转文字
# 快速转录会议录音whisper meeting_20240312.m4a --model turbo --language Chinese# 输出示例:# [00:00:00] 大家好,今天我们讨论一下 Q1 的销售情况...# [00:05:30] 关于产品路线图,我这边有几个建议...# [00:15:00] 最后总结一下今天的行动项...
场景 2:视频字幕制作
# 生成 SRT 字幕文件whisper video.mp4 --model medium --output_format srt --language Chinese# 直接导入视频编辑软件使用
场景 3:播客转文章
# 转录播客内容whisper podcast_ep50.mp3 --model turbo --output_format txt# 然后用 AI 工具整理成文章
场景 4:批量处理音频
# 批量转录目录下所有音频for f in *.m4a; do whisper "$f" --model turbo --output_dir ./transcriptsdone
场景 5:外语视频翻译
# 日语视频翻译成英文whisper japanese_video.mp4 --task translate --language Japanese# 输出英文文字
在 OpenClaw 中使用
通过对话触发
用户:帮我转录这个音频文件 /path/to/meeting.mp3AI:[调用 openai-whisper skill,生成转录文本]
用户:把这个视频转成字幕AI:[调用 openai-whisper skill,生成 SRT 字幕]
指定语言和模型
用户:用 large 模型转录这个中文音频 /path/to/audio.mp3AI:[使用 large 模型转录]
与 API 版本对比
| 特性 | 本地 Whisper | OpenAI Whisper API |
|---|---|---|
| 费用 | ||
| 隐私 | ||
| 离线 | ||
| 速度 | 取决于硬件 | |
| 准确率 | 相同 | 相同 |
| 文件大小限制 |
高级技巧
1. 使用 GPU 加速
# 安装 CUDA 版本的 PyTorchpip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118# 自动使用 GPUwhisper audio.mp3 --model large
2. 合并分段字幕
# 设置最小分段长度whisper audio.mp3 --word_timestamps True
3. 处理长音频
# Whisper 自动分段处理长音频,无需额外操作whisper long_podcast.mp3 --model turbo
4. 指定设备
# 强制使用 CPUwhisper audio.mp3 --device cpu# 使用指定 GPUwhisper audio.mp3 --device cuda:0
常见问题
Q: 第一次运行很慢?
A: 首次使用会自动下载模型(tiny 150MB, large 3GB),下载后就会很快。
Q: 中文识别准确吗?
A: 非常准确!建议使用 --language Chinese 参数提升效果。
Q: 支持方言吗?
A: 支持多种中文方言,包括粤语、四川话等。
Q: 可以处理背景噪音吗?
A: Whisper 有一定抗噪能力,但背景噪音大时建议先用音频处理工具降噪。
Q: 显存不够怎么办?
A: 使用更小的模型(tiny/base),或强制使用 CPU(--device cpu )。
总结
| 特性 | 说明 |
|---|---|
| 无 API 费用,本地运行 | |
| 数据不出本地 | |
| 支持 99 种语言 | |
| 下载模型后无需联网 | |
| 支持音频、视频、字幕输出 | |
| tiny 到 large,速度与准确率平衡 |