基于模型上下文协议(MCP)框架构建的多功能TTS(文本转语音)服务器。该服务器通过统一接口提供对多个TTS引擎的访问:
# 克隆仓库
git clone https://github.com/kristofferv98/MCP_tts_server.git
cd MCP_tts_server
# 创建虚拟环境并安装依赖
uv venv
source .venv/bin/activate # 在Windows上:.venv\Scripts\activate
uv pip install -e .
根据提供的.env.example创建一个.env文件:
cp .env.example .env
编辑.env文件,添加您的OpenAI API密钥:
OPENAI_API_KEY=your_openai_api_key_here
要使用此服务器与Claude Desktop:
安装服务器:
fastmcp install ./tts_mcp.py --name tts
或者,您可以手动将服务器添加到Claude Desktop的配置文件中:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json在mcpServers部分添加以下条目:
"kokoro_tts": {
"command": "uv",
"args": [
"--directory",
"/path/to/MCP_tts_server",
"run",
"tts_mcp.py"
]
}
使用uv的完整路径示例配置:
"kokoro_tTts": {
"command": "/Users/username/.local/bin/uv",
"args": [
"--directory",
"/Users/username/Documents/MCP_Servers/MCP_tts_server",
"run",
"tts_mcp.py"
]
}
服务器公开了以下MCP工具:
{
"description": "使用首选引擎将文本转换为语音,并将语音流传输给用户。AI的基础语音是Kokoro引擎,以保持AI个性的一致性。这个统一的功能提供了对Kokoro TTS(本地)和OpenAI TTS(云API)的访问。",
"name": "tts",
"parameters": {
"properties": {
"text": {"title": "文本", "type": "string"},
"engine": {"default": "kokoro", "title": "引擎", "type": "string"},
"speed": {"default": 1, "title": "速度", "type": "number"},
"voice": {"default": "", "title": "语音", "type": "string"},
"instructions": {"default": "", "title": "指令", "type": "string"}
},
"required": ["text"]
}
}
{
"description": "停止当前正在播放的音频(如果有),并清除队列中的所有待处理TTS请求。依赖后台工作者检测取消信号。",
"name": "tts_stop_playback_and_clear_queue",
"parameters": {
"properties": {}
}
}
{
"description": "提供基于研究的有效语音指令示例,适用于OpenAI TTS。",
"name": "tts_examples",
"parameters": {
"properties": {
"category": {"default": "general", "title": "类别", "type": "string"}
}
}
}
{
"description": "通过调用get_voice_info获取TTS指令。",
"name": "get_tts_instructions",
"parameters": {
"properties": {}
}
}
主要的使用方式是通过Claude Desktop或其他支持MCP的集成,如上所述。然而,您也可以直接运行服务器进行测试目的:
# 使用uv环境管理器运行
uv run python tts_mcp.py
# 或使用仅限Kokoro的简化版本
uv run python simple_tts_mcp.py
这将启动MCP服务器,使其可用于连接。
af_heartalloy, ash, ballad, coral, echo, fable, onyx, nova, sage, shimmergpt-4o-mini-tts在开发期间进行本地测试:
fastmcp dev ./tts_mcp.py
这将启动MCP Inspector界面,在那里您可以测试服务器的功能。
服务器使用FastMCP实现,并遵循MCP服务器开发的最佳实践:
本项目根据Apache许可证2.0发布 - 详情见LICENSE文件。
欢迎贡献!请随时提交Pull Request。