语音桥
 
用于AI编码助手的多引擎文本转语音。通过Claude Code插件、MCP服务器或CLI管道从Claude Code、Cursor或VS Code大声说出响应。
pip install ai-voice-bridge[edge] # Install with free edge-tts engine
voice-bridge test # Verify audio output
voice-bridge on # Enable always-on mode (optional)特性
- 默认免费 --edge-tts使用Microsoft Neural语音,不需要API密钥
- 5台发动机 --edge-tts、ElevenLabs、Kokoro(本地ONNX)、macOS等
- 文本安全过滤器 --在说话前删除代码块、机密、文件路径、URL和标记
- Claude代码插件 --停止钩子自动发出响应,MCP服务器用于基于工具的控制
- 语音发现 --浏览、按性别/地区过滤和交互式预览声音
先决条件
语音桥是一个 Python包 在您的设备上播放音频 本地机器它要求:
| 要求 | 详细信息 |
|---|---|
| Python 3.10+ | python3 --version 检查 |
| 点 | 通常与Python捆绑在一起。在某些Linux发行版上: sudo apt install python3-pip |
| 音频输出 | 扬声器或耳机——音频在本地播放,而不是通过网络播放 |
| 音频播放器 (Linux/Windows) | macOS:内置(afplay). Linux: mpv (首选)或 ffplay. 视窗: ffplay (首选)或 mpv |
音频播放器回退顺序:macOS使用 afplay (始终可用)。Linux尝试 mpv 然后 ffplayWindows尝试 ffplay 然后 mpv.
不支持:无头服务器、Docker容器、SSH会话和CI运行器通常缺少音频输出。语音桥将安装并运行MCP服务器,但 speak 如果没有音频播放器和声音硬件,命令将自动失败。快速开始
安装
# Recommended: edge-tts (free, 400+ voices)
pip install ai-voice-bridge[edge]
# Or with all engines
pip install ai-voice-bridge[all]
# Or minimal (macOS say / Linux espeak only)
pip install ai-voice-bridge测试
voice-bridge test # Speak a test phrase
voice-bridge engines # List available engines
voice-bridge setup # Interactive setup wizard设置向导将引导您完成:检测已安装的引擎、测试音频输出、可选地输入ElevenLabs API密钥(如果安装了SDK)、编写默认状态以及显示Claude Code集成选项。
使用
# Pipe text to speech
echo "Hello world" | vb-speak
# Choose an engine
echo "Hello" | vb-speak --engine edge-tts
echo "Hello" | vb-speak --engine say
# Modes
voice-bridge on # Always-on: every AI response spoken
voice-bridge off # Off: use "speak" keyword for single responses
voice-bridge status # Show current mode and engineClaude代码集成
选项1:作为插件安装(推荐)
claude plugin marketplace add Tomorrow-You/voice-bridge
claude plugin install voice-bridge@voice-bridge这将安装带有Stop钩子的插件(自动说话响应) /speak 技能和MCP服务器。自动安装 ai-voice-bridge[edge,mcp] 在第一次会议上。
选项2:手动吊钩设置
添加到您的 .claude/settings.json:
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "bash -c 'VB_HOOK=$(python3 -c \"import voice_bridge; import pathlib; print(pathlib.Path(voice_bridge.__file__).parent / \\\"integrations\\\" / \\\"claude_hook.sh\\\")\" 2>/dev/null) && [ -f \"$VB_HOOK\" ] && bash \"$VB_HOOK\"'",
"timeout": 5
}
]
}
]
}
}然后添加到您的 CLAUDE.md:
## Voice Bridge (TTS)
- **NEVER** use `` tags unless the user's message starts with "speak"
- When user starts with "speak", wrap your ENTIRE response in `...` tags
- Strip the "speak" keyword before processing
- Inside tags, write naturally -- no markdown, code blocks, or file paths选项2:始终开启模式
跳过 `` 标签约定完全:
voice-bridge on现在克劳德的每一个回答都是自动说出的。通过以下方式关闭 voice-bridge off.
挂钩细节
Stop钩子在后台运行,因此它不会阻塞Claude代码。它
- 从中提取文本 `` 标签(单圈模式)或全响应(始终开启模式)
- 说话前截断至2000个字符
- 使用回退链:配置引擎>espeak>say
- 日志到
~/.voice-bridge/voice-bridge.log(以1MB自动旋转,保留2个备份) - 跑
vb-speak --stream用于逐句回放
发动机
| 引擎 | 成本 | 质量 | 设置 | 平台 | 默认语音 |
|---|---|---|---|---|---|
| 边缘tts | 免费 | 高(神经) | pip install ai-voice-bridge[edge] | 全部 | en-US-GuyNeural |
| 十一实验室 | 已付 | 最高 | pip install ai-voice-bridge[elevenlabs] +API密钥 | 全部 | George(JBFqnCBsd6RMkjVDRZzb),型号 eleven_flash_v2_5 |
| 心 | 免费 | 好 | pip install ai-voice-bridge[kokoro] +模型下载 | 全部(仅英文) | bm_lewis |
| 说 | 免费 | 基本 | 内置 | macOS | Samantha |
| espeak | 免费 | 基本 | apt install espeak-ng | Linux | en |
当发动机设置为 auto (默认),语音桥按以下顺序选择第一个可用的:edge-tts>say>espeak>kokoro>elevenlabs。只有在安装了SDK并且配置了有效的API密钥的情况下,ElevenLabs才被视为“可用”——如果没有凭据,它将永远不会自动选择。
发现声音
voice-bridge voices # List voices for current engine
voice-bridge voices edge-tts # List voices for a specific engine
# Filter by gender and/or locale
voice-bridge voices edge-tts --gender Female --locale en-US
# Preview a specific voice
voice-bridge voices edge-tts --preview en-US-AriaNeural
# Interactively audition voices (next/select/quit after each)
voice-bridge voices edge-tts --gender Female --locale en-US --preview
# Random sample of 3 voices
voice-bridge voices edge-tts --sample 3 --preview筛选选项: --gender (男/女)与edge tts和kokoro合作。 --locale (例如en-US、en-GB)使用edge-tts和say。 --sample N 随机选取N个声音。全部与 --preview 互动试听。
ElevenLabs预览版在可用时使用免费预先录制的样本(不消耗API信用)。
切换引擎
voice-bridge engine edge-tts # Free neural voices
voice-bridge engine elevenlabs # Premium cloud
voice-bridge engine kokoro # Local offline
voice-bridge engine say # macOS built-in
voice-bridge engine espeak # Linux built-in
voice-bridge engine auto # Best available (default)ElevenLabs设置
pip install ai-voice-bridge[elevenlabs]
voice-bridge setup # Prompts for your ElevenLabs API key
# Or manually: create ~/.voice-bridge/.env with ELEVENLABS_API_KEY=your-key
voice-bridge engine elevenlabs
voice-bridge testKokoro设置(离线)
pip install ai-voice-bridge[kokoro]
# Download model files (~200MB) from:
# https://github.com/thewh1teagle/kokoro-onnx/releases/tag/model-files-v1.0
# Place in: ~/.voice-bridge/models/ (or $VOICE_BRIDGE_HOME/models/)
voice-bridge engine kokoro
voice-bridge test配置
语音桥将配置存储在 ~/.voice-bridge/ (macOS), ~/.local/share/voice-bridge/ (Linux,尊重 XDG_DATA_HOME),或 %APPDATA%\voice-bridge\ (Windows)。
用覆盖 VOICE_BRIDGE_HOME 环境变量。
| 文件 | 目的 |
|---|---|
.env | API密钥(ElevenLabs) |
.state | 运行时状态(模式、发动机、速度、声音) |
models/ | Kokoro ONNX模型文件 |
voice-bridge.log | 钩子执行日志(以1MB自动轮换,2个备份) |
状态变量
这 .state file是一个shell源键值文件。所有值都是可选的——如果未设置,则应用默认值。
| 变量 | 默认值 | 描述 |
|---|---|---|
VOICE_BRIDGE_MODE | off | 模式: off (单圈)或 always (始终打开) |
VOICE_BRIDGE_ENGINE | auto | 发动机名称或 auto |
VOICE_BRIDGE_EDGE_VOICE | en-US-GuyNeural | 边缘tts语音 |
VOICE_BRIDGE_EDGE_RATE | +0% | 边缘tts速率(例如。 +30%, -10%) |
VOICE_BRIDGE_ELEVENLABS_SPEED | 1.0 | ElevenLabs速度(0.7–1.2) |
VOICE_BRIDGE_KOKORO_VOICE | bm_lewis | Kokoro语音名称 |
VOICE_BRIDGE_KOKORO_SPEED | 1.4 | 科科罗速度倍增器 |
VOICE_BRIDGE_SAY_RATE | 200 | macOS每分钟说单词数 |
VOICE_BRIDGE_ESPEAK_RATE | 175 | 每分钟单词数 |
文本安全过滤器
在任何文本到达TTS引擎之前,语音桥会删除:
- 代码块 (围栏 ```
```和内联``) - 秘密:OpenAI/拟人键(
sk-...),GitHub代币(ghp_,gho_),AWS密钥(AKIA...),PEM私钥,64+字符十六进制字符串 - 文件路径:Unix(
/Users/...,/home/...)和Windows(C:\Users\...) - 网址:
http://和https:// - 标记语言:标题、粗体/斜体标记、列表项目符号、表格行
文本在最近的句子边界处被截断为4000个字符(. ).Claude钩子在将文本传递给 vb-speak.
CLI 参考
# Control
voice-bridge on # Always-on mode
voice-bridge off # Single-turn mode (default)
voice-bridge status # Show mode, engine, config
voice-bridge test # Test audio output
voice-bridge engines # List all engines with install status
voice-bridge setup # Interactive setup wizard
# Engine config
voice-bridge engine [name] # Get/set engine
voice-bridge voice [id] # Set voice for current engine
voice-bridge voices [engine] # List available voices
voice-bridge speed [val] # Set engine speed (see below)
# Voice discovery
voice-bridge voices edge-tts --gender Female --locale en-US # Filter
voice-bridge voices edge-tts --preview en-US-AriaNeural # Preview one
voice-bridge voices edge-tts --gender Female --preview # Interactive
voice-bridge voices edge-tts --sample 3 --preview # Random sample
# Pipe to speech
echo "text" | vb-speak # Default engine
echo "text" | vb-speak --engine edge-tts # Specific engine
echo "text" | vb-speak --voice Aria # Override voice for this call
echo "text" | vb-speak --stream # Stream sentence-by-sentence
echo "text" | vb-speak --dry-run # Print filtered text only流媒体模式 (--stream):读取stdin,在句子边界分割文本(. , ! , ? ),并在完成每个句子时说出。对于边缘tts,句子会排队,以便在当前句子播放的同时生成下一个句子。
速度控制
每台发动机接受不同的速度格式:
| 引擎 | 格式 | 默认值 | 示例 |
|---|---|---|---|
| 边缘tts | 百分比字符串 | +0% | voice-bridge speed +30% |
| 十一个实验室 | 浮动(0.7–1.2) | 1.0 | voice-bridge speed 1.1 |
| 心 | 正浮动 | 1.4 | voice-bridge speed 1.8 |
| 说 | 每分钟字数 | 200 | voice-bridge speed 250 |
| espeak | 每分钟字数 | 175 | voice-bridge speed 220 |
速度适用于当前处于活动状态的任何发动机。与核对 voice-bridge speed (无值)。
MCP服务器
Voice Bridge包括一个MCP(模型上下文协议)服务器,因此任何兼容MCP的工具都可以大声朗读文本。
npm垫片(npx ai-voice-bridge):npm包是一个自动安装Python包的瘦包装器。它需要Python 3.10+和pipPATH启动时,它会检查音频播放器,如果没有找到,则发出警告。看 先决条件 以满足全部要求。
使用Claude Desktop进行设置
添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"voice-bridge": {
"command": "python3",
"args": ["-m", "voice_bridge.mcp.server"]
}
}
}或者在npm发布后,使用npm shim:
{
"mcpServers": {
"voice-bridge": {
"command": "npx",
"args": ["ai-voice-bridge"]
}
}
}使用游标/VS代码进行设置
在编辑器的MCP设置中添加相同的MCP服务器配置。配置格式与Claude Desktop相同。
使用Claude代码进行设置
claude mcp add voice-bridge -- python3 -m voice_bridge.mcp.serverMCP工具
| 工具 | 参数 | 说明 |
|---|---|---|
speak | text (必填), engine (可选) | 大声朗读文本。可选地覆盖此调用的引擎。 |
set_engine | name (必填) | 切换默认TTS引擎(auto, edge-tts, elevenlabs, kokoro, say, espeak) |
get_status | _(无)_ | 显示当前模式、发动机和可用发动机 |
list_voices | engine (可选) | 列出可用声音。如果省略,则默认为当前引擎。 |
使用MCP支架进行安装
pip install ai-voice-bridge[mcp]这将安装 voice-bridge-mcp 命令作为替代 python3 -m voice_bridge.mcp.server.
发展
git clone https://github.com/Tomorrow-You/voice-bridge.git
cd voice-bridge
python3 -m venv .venv && source .venv/bin/activate
pip install -e ".[all,dev]"
pytest许可证
MIT。看 许可证 了解详情。
这 edge-tts 可选依赖关系在GPL-3.0下获得许可。它不包含在基础安装中。
