修复并集成说话者分离功能

修复:
- kb-whisper-diarization/whisper_diarization.py 变量名 bug

集成:
- kb-workflow/SKILL.md 步骤5 添加说话者分离选项
- 自动检测 HF_TOKEN 选择识别模式
- 子技能清单添加 kb-whisper-diarization

文档:
- kb-whisper-diarization/SKILL.md 完善 HF_TOKEN 获取步骤
This commit is contained in:
2026-02-15 23:18:11 +08:00
parent 70736bce2e
commit 3dc8d246d0
3 changed files with 68 additions and 9 deletions
+29 -5
View File
@@ -18,12 +18,36 @@
| `WHISPER_CPP_PATH` | whisper.cpp 安装路径 | `~/whisper.cpp` |
| `HF_TOKEN` | HuggingFace Token | `hf_xxx...` |
### 获取 HuggingFace Token
### 获取 HuggingFace Token(必需)
pyannote.audio 需要从 HuggingFace 下载模型,需要先:
1. 注册 HuggingFace 账号:https://huggingface.co
2. 申请模型访问权限:https://huggingface.co/pyannote/speaker-diarization
3. 创建 Token:https://huggingface.co/settings/tokens
pyannote.audio 需要从 HuggingFace 下载模型,按以下步骤操作:
**步骤 1: 注册/登录 HuggingFace**
- 访问 https://huggingface.co
- 注册或登录账号
**步骤 2: 申请模型访问权限**
需要申请以下两个模型的访问权限(点击页面上的 "Access repository" 按钮):
- https://huggingface.co/pyannote/speaker-diarization
- https://huggingface.co/pyannote/segmentation
> ⚠️ 申请后需要等待几分钟到几小时才能获得访问权限
**步骤 3: 创建 Access Token**
1. 访问 https://huggingface.co/settings/tokens
2. 点击 "New token"
3. 选择 "Read" 权限
4. 复制生成的 token(以 `hf_` 开头)
**步骤 4: 设置环境变量**
```bash
# 添加到 ~/.kb_env 文件
echo 'export HF_TOKEN="hf_xxxxxxxxxxxxxxxxxxxxxx"' >> ~/.kb_env
source ~/.kb_env
# 验证
echo $HF_TOKEN
```
## 使用方法
@@ -320,7 +320,7 @@ def main():
result = merge_results(whisper_txt, whisper_srt, diarization, output_dir, basename)
# 清理临时音频
if audio_path != input_path and audio_path.endswith('_audio.wav'):
if audio_path != input_file and audio_path.endswith('_audio.wav'):
try:
os.remove(audio_path)
except Exception:
+38 -3
View File
@@ -191,15 +191,49 @@ python3 /path/to/bilibili_content.py --id "[ID]" --type subtitle-download --outp
python3 kb_workflow.py --content
```
2. 启动子代理调用 kb-whisper(传入视频路径):
2. **选择识别方式**:
**方式 A: 普通识别(不区分说话者)**
```bash
# 必须传入 --output 完整路径
python3 /path/to/whisper.py --input [video_path] --model base --output [content_dir]
```
**方式 B: 带说话者分离(推荐用于访谈、对话类视频)**
```bash
# 先检查 HF_TOKEN 环境变量
if [ -z "$HF_TOKEN" ]; then
echo "⚠️ HF_TOKEN 未设置,将使用普通识别(不区分说话者)"
python3 /path/to/whisper.py --input [video_path] --model base --output [content_dir]
else
echo "✅ 使用说话者分离模式"
python3 /path/to/whisper_diarization.py --input [video_path] --model base --diarize --output [content_dir]
fi
```
3. 等待 Whisper 完成(定时汇报进度)
4. 解析输出 JSON,生成 content 文件供步骤6使用
4. 解析输出 JSON:
- 普通识别:生成 `xxx.json`, `xxx.txt`, `xxx.srt`
- 说话者分离:生成 `xxx_diarized.json`, `xxx_diarized.txt`, `xxx_diarized.srt`
#### 说话者分离环境变量
| 变量名 | 用途 | 获取方式 |
|--------|------|----------|
| `HF_TOKEN` | HuggingFace Token | 见下方说明 |
**获取 HuggingFace Token:**
1. 注册 HuggingFace 账号:https://huggingface.co/join
2. 申请 pyannote 模型访问权限:
- https://huggingface.co/pyannote/speaker-diarization (点击 "Access")
- https://huggingface.co/pyannote/segmentation (点击 "Access")
3. 创建 Token:https://huggingface.co/settings/tokens → New token → Read
4. 设置环境变量:
```bash
# 添加到 ~/.kb_env
echo 'export HF_TOKEN="hf_xxxxxxxxxxxxxxxxxxxxxx"' >> ~/.kb_env
source ~/.kb_env
```
### 步骤 6: 深度分析
@@ -255,6 +289,7 @@ python3 kb_workflow.py --archive-file "[分析报告文件路径]"
| 4 | kb-bilibili-content | `--id "BVxxx" --type subtitle-download` | `{p}_{id}.srt` | 如果没有字幕是正常的 |
| 4 | kb-bilibili-content | `--id "BVxxx" --type video` | `{p}_{id}.mp4` | 如果需要下载视频 |
| 5 | kb-whisper | `--input xxx.mp4 --model base` | `{p}_{id}.json`, `{p}_{id}.txt` | 仅当没有官方字幕时执行 |
| 5 | kb-whisper-diarization | `--input xxx.mp4 --model base --diarize` | `{p}_{id}_diarized.json` | 带说话者分离(需 HF_TOKEN) |
| 6 | kb-deep-analyzer | `--metadata x.meta.json --content x.json --output x.md --provider zhipu --model glm-5` | `{p}_{id}.md` | **使用 g5 模型,必须成功** |
## 条件分支逻辑