自动同步: 2026-03-15 02:10

This commit is contained in:
2026-03-15 02:10:07 +08:00
parent c8c4b780c8
commit b1476136aa
31 changed files with 1119 additions and 2646 deletions
+53 -109
View File
@@ -1,40 +1,44 @@
---
name: kb-whisper
description: 本地语音识别 - 使用 Whisper.cpp 将音视频转文字
description: 本地语音识别,支持音视频转文字(基于 Whisper.cpp)
---
# KB Whisper Skill
**kb-whisper** - 本地语音识别,使用 Whisper.cpp 将音视频文件转换为文本、字幕和 JSON 格式。
**kb-whisper** - 本地语音识别,使用 Whisper.cpp 将音视频文件转换为文本、字幕和 JSON 格式输出。
## 什么时候使用
- kb-workflow 步骤 4:视频无官方字幕时进行语音识别
- 需要将音视频转为文字
当用户需要:
- 将视频/音频文件转换为文字
- 生成视频字幕(SRT 格式)
- 获取带时间戳的详细识别结果
## 环境变量
| 变量名 | 必需 | 说明 |
|--------|------|------|
| `WHISPER_CPP_PATH` | 是 | whisper.cpp 安装路径 |
在使用之前,必须检查环境变量是否已经设置。
## 命令
| 变量名 | 用途 | 示例 |
|--------|------|------|
| `WHISPER_CPP_PATH` | whisper.cpp 安装路径 | `~/whisper.cpp` |
## 使用方法
```bash
# 基本用法
python3 whisper.py --input video.mp4
python whisper.py --input video.mp4
# 指定模型(推荐 base)
python3 whisper.py --input video.mp4 --model base
# 指定模型(默认 tiny)
python whisper.py --input video.mp4 --model base
# 指定输出目录
python3 whisper.py --input video.mp4 --output ./output
python whisper.py --input video.mp4 --output ./output
# 后台异步执行
python3 whisper.py --input video.mp4 --background
# 异步执行(推荐)
python whisper.py --input video.mp4 --background
```
## 参数说明
## 命令参数
| 参数 | 说明 | 默认值 |
|------|------|--------|
@@ -45,94 +49,51 @@ python3 whisper.py --input video.mp4 --background
## 模型选项
| 模型 | 速度 | 精度 | 推荐场景 |
|------|------|------|---------|
| `tiny` | 最快 | 较低 | 快速预览 |
| `base` | 快 | 良好 | **推荐** |
| `small` | 中等 | 高 | 精确识别 |
| `medium` | 慢 | 很高 | 专业场景 |
| `large` | 最慢 | 最高 | 最高精度 |
- `tiny` - 最小模型,速度快,精度较低(推荐快速识别)
- `base` - 基础模型,平衡速度和精度(推荐)
- `small` - 小型模型,精度更高,速度较慢
- `medium` - 中型模型,高精度
- `large` - 大型模型,最高精度,速度慢
## 输出格式 Schema
## 输出文件
### 必需字段
对于输入 `video.mp4`,将生成:
| 字段 | 类型 | 说明 |
|------|------|------|
| `success` | boolean | 是否识别成功 |
| `input_file` | string | 输入文件路径 |
| `model` | string | 使用的模型 |
- `video.json` - 详细结果(包含时间戳、分段信息)
- `video.srt` - 字幕格式文件
- `video.txt` - 纯文本内容
### 可选字段
## 输出格式示例
| 字段 | 类型 | 说明 |
|------|------|------|
| `output_files` | object | 输出文件路径 |
| `duration_seconds` | number | 音频时长 |
| `segments` | array | 识别分段 |
| `error` | string | 错误信息 |
## 成功示例
### JSON 格式
```json
{
"success": true,
"input_file": "content/downloads/bilibili_BV1xx411c7mD.mp4",
"model": "base",
"input_file": "video.mp4",
"model": "tiny",
"output_files": {
"json": "content/bilibili_BV1xx411c7mD.json",
"txt": "content/bilibili_BV1xx411c7mD.txt",
"srt": "content/bilibili_BV1xx411c7mD.srt"
"json": "video.json",
"srt": "video.srt",
"txt": "video.txt"
},
"duration_seconds": 630.5,
"duration_seconds": 120.5,
"segments": [
{
"id": 0,
"start": 0.0,
"end": 3.2,
"text": "这是第一段字幕"
},
{
"id": 1,
"start": 3.2,
"end": 6.5,
"text": "这是第二段字幕"
}
]
}
```
## 错误示例
## Workflow 中的使用
### 模型未下载
```json
{
"success": false,
"error": "模型文件不存在",
"model": "base",
"suggestion": "请运行: cd ~/whisper.cpp && ./models/download-ggml-model.sh base"
}
```
### 文件不存在
```json
{
"success": false,
"error": "输入文件不存在",
"input_file": "content/downloads/missing.mp4"
}
```
### 内存不足
```json
{
"success": false,
"error": "内存不足,无法加载模型",
"suggestion": "尝试使用更小的模型(tiny/base)"
}
```bash
# 步骤4之后:如果已有音频但无字幕,可以使用 whisper
python whisper.py --input ${video_path} --model base --background
```
## 安装
@@ -142,39 +103,22 @@ python3 whisper.py --input video.mp4 --background
git clone https://github.com/ggerganov/whisper.cpp.git ~/whisper.cpp
# 2. 编译
cd ~/whisper.cpp && make
cd ~/whisper.cpp
make
# 3. 下载模型
./models/download-ggml-model.sh base
# 3. 下载模型(tiny)
./models/download-ggml-model.sh tiny
# 4. 设置环境变量
echo 'export WHISPER_CPP_PATH="$HOME/whisper.cpp"' >> ~/.kb_env
source ~/.kb_env
# 4. 下载更多模型(可选)
# ./models/download-ggml-model.sh base
# ./models/download-ggml-model.sh small
# 5. 复制技能
cp -r kb-whisper/ ~/.openclaw/skills/
```
## 在 kb-workflow 中的使用
```bash
# 步骤 4:语音识别(当 has_subtitle=false 时)
python3 ~/.openclaw/skills/kb-whisper/whisper.py \
--input "content/downloads/bilibili_BV1xx411c7mD.mp4" \
--model base \
--output "content/"
# 输出:
# - bilibili_BV1xx411c7mD.json (完整结果)
# - bilibili_BV1xx411c7mD.txt (纯文本)
# - bilibili_BV1xx411c7mD.srt (字幕文件)
# 完成后进入步骤 5(深度分析)
# 5. 复制技能到 skills 目录
cp -r kb-whisper/ ~/skills/
```
## 注意事项
- **耗时操作**:语音识别可能需要几分钟到几十分钟,取决于视频长度
- **异步执行**:推荐使用 `--background` 参数
- **模型选择**:base 模型平衡速度和精度,适合大多数场景
- **文件格式**:支持 MP3、MP4、WAV、FLAC、OGG、M4A 等常见格式
- **异步执行**: 使用 `--background` 参数时,命令会在后台运行,不阻塞主代理
- **模型选择**: tiny 模型适合快速识别,base 模型适合一般用途,large 模型适合高精度需求
- **文件格式**: 支持 MP3、MP4、WAV、FLAC、OGG、M4A 等常见格式