feat: 添加本地字幕生成功能

- 新增 subtitle_generator.py 核心模块
  - AudioDownloader: 使用 yt-dlp 下载视频音频
  - WhisperTranscriber: Whisper 语音识别器
  - SubtitleFormatter: SRT 格式化器
  - SubtitleCache: 缓存管理器
  - SubtitleGenerator: 统一接口

- 集成到 pipeline.py
  - 添加 _ensure_subtitle() 方法
  - 自动检测无字幕视频并生成字幕
  - 支持缓存机制避免重复处理

- 更新配置文件
  - config.yaml.example 添加字幕配置项
  - requirements.txt 添加依赖包

- 文档更新
  - SKILL.md 添加字幕生成说明
  - SUBTITLE_FEATURE.md 详细功能文档

- 测试脚本
  - test_subtitle_generator.py 完整测试套件

特性:
- 本地处理,数据不上传,隐私安全
- 支持中英文识别及自动检测
- 多种模型可选(tiny/base/small/medium/large)
- 智能缓存,提升处理速度
- 完善的错误处理和日志输出
This commit is contained in:
OpenClaw Agent
2026-02-07 01:57:13 +08:00
parent 42a8dd9642
commit 8bce4ac23b
7 changed files with 1382 additions and 92 deletions
+30
View File
@@ -135,6 +135,28 @@ https://www.youtube.com/watch?v=dQw4w9WgXcQ
https://zhuanlan.zhihu.com/p/123456789
```
### 启用字幕生成(可选)
如果视频没有字幕,可以启用本地字幕生成功能:
```bash
# 1. 安装依赖
pip install openai-whisper yt-dlp torch
# 2. 启用配置(编辑 config.yaml)
subtitle:
enabled: true
model: base # 推荐使用 base 模型
```
**说明:**
- 使用 Whisper 本地模型,数据不上传,隐私安全
- 首次使用会自动下载模型文件(~74MB)
- 10分钟视频约需 2-5 分钟处理时间(取决于硬件)
- 生成的字幕会自动缓存,重复使用无需重新生成
**详细文档:** 见 `SUBTITLE_FEATURE.md`
### 方式2: 使用命令
显式调用命令添加内容:
@@ -322,6 +344,14 @@ chunking:
max_chunk_duration_seconds: 1800 # 最大分段时长
long_video_threshold: 1800 # 长视频阈值 (30分钟)
# 字幕生成配置(新增)
subtitle:
enabled: false # 是否启用自动生成字幕
model: base # Whisper 模型大小: tiny/base/small/medium/large
language: null # 语言代码: zh/en/null(自动检测)
cache_dir: cache/subtitles # 字幕缓存目录
audio_cache_dir: cache/audio # 音频缓存目录
# 数据源配置
sources:
bilibili: