feat: transcribe_voice 新增 whisper.cpp 后端(macOS Metal GPU 加速) (#78)

* Add transcribe_chat_whisper_cpp.py: macOS whisper.cpp transcription

whisper.cpp variant of transcribe_chat.py for Apple Silicon Macs.

Advantages over transcribe_chat.py:
- Uses whisper-cpp CLI with Metal/ANE GPU acceleration (3-5x faster)
- No PyTorch or openai/whisper Python dependency
- Same idempotent, crash-safe design as transcribe_chat.py
- Auto-detects model from common macOS locations:
  ~/Library/Application Support/whisper-cpp/,
  ~/Library/Application Support/Recordly/whisper/, etc.
- --model-size flag for automatic download if no model found
- Configurable --language (default: zh) and --threads

Usage: python3 transcribe_chat_whisper_cpp.py <input.json> [output.json]

* refactor: 将 whisper.cpp 转为后端选项集成到 mcp_server.py 中

根据 PR #78 review 反馈,将独立的 transcribe_chat_whisper_cpp.py 重构为
mcp_server.py 中的 whisper_cpp 后端,与 PR #66 OpenAl 后端模式对齐。

变更:
- mcp_server.py: 新增 _transcribe_whisper_cpp()、_resolve_whisper_cpp_binary()、
  _resolve_whisper_cpp_model(),更新 _resolve_active_backend()/_cache_signature()/
  _transcribe() 以分发至 whisper_cpp 后端
- transcribe_chat.py: 统一入口 mcp_server._transcribe 自动支持新后端,
  仅补充了 backend 打印信息
- 删除 transcribe_chat_whisper_cpp.py

config.json 启用方式:
  "transcription_backend": "whisper_cpp",
  "whisper_cpp_binary": "...",    # 可选,默认自动检测
  "whisper_cpp_model": "...",     # 可选,默认自动检测
  "whisper_cpp_language": "zh",   # 可选
  "whisper_cpp_threads": 4          # 可选,默认自动检测

* docs: 在语音转录隐私章节补充 whisper.cpp 后端说明

根据 PR #78 review 反馈,在 README.md ⚠️ 语音转录隐私章节
新增 whisper.cpp 后端(macOS Metal GPU 加速)的配置说明、隐私
属性和回退行为,与 OpenAI 后端并列。
This commit is contained in:
Davy
2026-05-11 20:42:53 -07:00
committed by GitHub
parent 67de4a1d0c
commit fe5cc633ff
3 changed files with 148 additions and 7 deletions

View File

@@ -221,9 +221,22 @@ claude mcp add wechat -- python C:\Users\你的用户名\wechat-decrypt\mcp_serv
- 成本:约 $0.006 / 分钟OpenAI 计价)
- 文件 > 25MB 在上传前被拒绝OpenAI 上限)
- 首次启用云后端时 stderr 会打一行警告
- `transcription_backend``openai_api_key` 任一缺失时静默回退 local
- 切换后端后旧缓存条目backend 不匹配)会自动重新转录
如需切换到 whisper.cpp 后端macOS Metal GPU 加速3-5x 更快),在 `config.json` 中:
```json
{
"transcription_backend": "whisper_cpp"
}
```
数据全程留在本机,不上传。需要 `brew install whisper-cpp` 并下载模型(自动检测常见路径,或通过 `whisper_cpp_binary` / `whisper_cpp_model` 指定)。
所有后端共用以下行为:
- 首次启用 openai 或 whisper_cpp 后端时 stderr 会打一行警告
- openai: `openai_api_key` 缺失时静默回退 local
- whisper_cpp: 二进制文件未找到时静默回退 local
- 切换后端后旧缓存条目backend 不匹配)自动重新转录
**[查看使用案例 →](USAGE.md)**