基于可插拔 ASR 引擎的多语言字幕生成技能,支持 Faster-Whisper(优先)和 OpenAI Whisper(兜底),自动检测 GPU 加速,支持 99+ 语言。
字幕生成是纯执行任务, 禁止 使用 sessions_spawn 或子代理来执行命令,原因:
exec background:true 效率最高bash
exec background:true command:"python3 ~/.openclaw/workspace/skills/subtitle-generator/scripts/main.py <视频文件> [srt|vtt] [语言] --notify"
⚠️ 必须使用 background:true,禁止前台执行阻塞主窗口。
步骤 0(首次自动): engines/ init.py 在首次导入时自动检测 ~/.whisper-venv 是否存在,不存在时自动创建 venv 并安装依赖(faster-whisper 优先,openai-whisper 兜底),GPU 可用时自动启用 CUDA 加速。AI 无需手动干预。
收到任务后 立即回复 用户:「🎬 字幕生成已启动(后台),完成后我会通知你。」
使用 exec background:true 启动任务
任务完成后(进程退出码为 0 或出错) 必须 kill 相关进程
通过 openclaw system event --mode now 唤醒 AI,再由 AI 使用 message 工具发送完成通知给用户
openclaw system event 只唤醒 AI,不发送 Telegram/Discord 等消息message 工具才能触达用户将字幕文件复制到视频同目录
清理 /tmp 中的临时文件
sessions_spawn / 子代理执行此任务exec command:"..."(无 background:true)任务启动时:
text
🎬 字幕生成已启动(后台),完成后我会通知你。
文件:xxx.mp4 | 格式:SRT | 语言:中文
Python 脚本输出 【字幕生成完成】 或 【字幕生成失败】 标记后,AI 被唤醒时使用 message 工具发送:
python
message(
action="send",
# 不传 channel 参数,自动路由到用户当前所在的聊天平台
message="✅ 字幕生成完成\n文件:xxx.srt | 条数:356\n路径:C:\\Users\\xxx\\Videos\\temp\\xxx.srt"
)
⚠️ 必须省略 channel 参数,这样才能兼容所有 OpenClaw 支持的聊天工具(Telegram / Discord / WhatsApp / Slack 等)。
bash
python ~/.openclaw/workspace/skills/subtitle-generator/scripts/main.py <video> [srt|vtt] [language] [--notify]
bash
# English video, SRT subtitles
python ~/.openclaw/workspace/skills/subtitle-generator/scripts/main.py video.mp4 srt en --notify
# Japanese video, VTT subtitles
python ~/.openclaw/workspace/skills/subtitle-generator/scripts/main.py video.mp4 vtt ja --notify
# Chinese video, auto language detection
python ~/.openclaw/workspace/skills/subtitle-generator/scripts/main.py video.mp4 srt zh --notify
# Auto-detect any Whisper-supported language
python ~/.openclaw/workspace/skills/subtitle-generator/scripts/main.py video.mp4 srt --notify
Whisper 支持 99+ 语言。常用语言代码:
CodeLanguageenEnglishzh中文 (Chinese)ja日本語 (Japanese)ko한국어 (Korean)frFrançaisdeDeutschesEspañolruРусский
不传语言参数 = 自动检测。
faster-whisper 使用 CTranslate2 作为推理引擎,运行时自动检测并启用 GPU:
系统GPU加速方式说明Windows + NVIDIACUDAcuDNN + CUDACTranslate2 自动加载macOS M1/M2/M3/M4MetalApple GPU需安装 Metal 版 CTranslate2(见下)macOS IntelCPU—慢但可用Linux + NVIDIACUDAcuDNN + CUDACTranslate2 自动加载CPU-only—降级运行所有平台均支持
faster-whisper 默认不包含 Metal 加速,手动安装 Metal 版可获得显著提速:
bash
# 先激活 venv,再安装 Metal 版 CTranslate2
~/.whisper-venv/bin/pip install \
--extra-index-url https://download.pytorch.org/whl/metal \
faster-whisper
安装后运行时日志会显示 Using device Metal,表示 Metal 加速已启用。
PriorityEngineNotes1 (preferred)faster-whisperCTranslate2, 2-4x faster, lower RAM2 (fallback)openai-whisperPyTorch, better compatibility
Engine is auto-selected. No manual configuration needed.
字幕文件生成在视频同目录:
text
video.mp4
video.srt ← auto-generated
faster-whisper or openai-whisper (auto-selected, auto-installed)ffmpeg (系统级,必须提前安装)ffmpeg-python (Python binding, auto-installed)系统安装命令Windowswinget install ffmpeg 或 https://ffmpeg.org/download.htmlmacOSbrew install ffmpegLinuxsudo apt install ffmpeg 或 sudo yum install ffmpeg
⚠️ ffmpeg 缺失时脚本会报错并给出对应系统的安装提示。