每天一个好用的 OpenClaw Skill:免费语音转文字,无需 API 本地运行
你是否遇到过这些场景?
• 🎙️ 会议录音转文字 — 2 小时会议,手动转录太费时 • 📹 视频字幕制作 — 想给视频加字幕,但不想花钱请人 • 🎧 播客内容整理 — 想把音频变成文章,手动整理太累 • 📝 采访录音整理 — 记者采访、用户访谈,转录工作量大 • 🔒 隐私敏感内容 — 不想上传到云端,担心数据泄露
openai-whisper 就是你的本地语音转文字神器!
什么是 openai-whisper?
OpenAI Whisper 是 OpenAI 开源的自动语音识别(ASR)模型,特点是:
安装方法
方法一:使用 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 | ||||
base | ||||
small | ||||
medium | ||||
large | ||||
turbo |
推荐:
• 日常使用: turbo(速度与准确率平衡)• 快速转录: base或small• 最高准确率: large
# 使用 turbo 模型(默认)
whisper audio.mp3 --model turbo
# 使用 small 模型(更快)
whisper audio.mp3 --model small
# 使用 large 模型(最准确)
whisper audio.mp3 --model large支持的音频格式
Whisper 支持几乎所有常见音频/视频格式:
实用参数详解
–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 | ||
vtt | ||
json | ||
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 ./transcripts
done场景 5:外语视频翻译
# 日语视频翻译成英文
whisper japanese_video.mp4 --task translate --language Japanese
# 输出英文文字在 OpenClaw 中使用
通过对话触发
用户:帮我转录这个音频文件 /path/to/meeting.mp3
AI:[调用 openai-whisper skill,生成转录文本]用户:把这个视频转成字幕
AI:[调用 openai-whisper skill,生成 SRT 字幕]指定语言和模型
用户:用 large 模型转录这个中文音频 /path/to/audio.mp3
AI:[使用 large 模型转录]与 API 版本对比
高级技巧
1. 使用 GPU 加速
# 安装 CUDA 版本的 PyTorch
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# 自动使用 GPU
whisper audio.mp3 --model large2. 合并分段字幕
# 设置最小分段长度
whisper audio.mp3 --word_timestamps True3. 处理长音频
# Whisper 自动分段处理长音频,无需额外操作
whisper long_podcast.mp3 --model turbo4. 指定设备
# 强制使用 CPU
whisper audio.mp3 --device cpu
# 使用指定 GPU
whisper 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)。
总结
一句话总结:免费、隐私安全、离线可用的语音转文字神器。
下期预告
下期 Skill:github — GitHub 自动化,开发者必备神器