语音MCP服务器
使用Kokoro TTS模型提供文本到语音功能的模型上下文协议服务器。
配置
可以使用以下环境变量配置服务器:
| 变量 | 描述 | 默认值 | 有效范围 |
|---|---|---|---|
MCP_DEFAULT_SPEECH_SPEED | 文本转语音的默认速度倍数 | 1.1 | 0.5到2.0 |
MCP_DEFAULT_VOICE | 文本转语音的默认语音 | af_bella | 任何有效的语音ID |
在光标中:
{
"mcpServers": {
"speech": {
"command": "npx",
"args": [
"-y",
"speech-mcp-server"
],
"env": {
"MCP_DEFAULT_SPEECH_SPEED": 1.3,
"MCP_DEFAULT_VOICE": "af_bella"
}
}
}
}特性
- 🎯 使用Kokoro TTS模型的高质量文本到语音转换
- 🗣️ 多种语音选项可用
- 🎛️ 可定制的语音参数(语音、速度)
- 🔌 MCP兼容接口
- 📦 易于安装和设置
- 🚀 不需要API密钥
安装
# Using npm
npm install speech-mcp-server
# Using pnpm (recommended)
pnpm add speech-mcp-server
# Using yarn
yarn add speech-mcp-server用法
运行服务器:
# Using default configuration
npm start
# With custom configuration
MCP_DEFAULT_SPEECH_SPEED=1.5 MCP_DEFAULT_VOICE=af_bella npm start服务器提供以下MCP工具:
text_to_speech:基本的文本到语音转换text_to_speech_with_options:可定制速度的文本转语音list_voices:列出所有可用的声音get_model_status:检查TTS模型的初始化状态
发展
# Clone the repository
git clone
cd speech-mcp-server
# Install dependencies
pnpm install
# Start development server with auto-reload
pnpm dev
# Build the project
pnpm build
# Run linting
pnpm lint
# Format code
pnpm format
# Test with MCP Inspector
pnpm inspector可用工具
1.文本到语音
使用默认设置将文本转换为语音。
{
"type": "request",
"id": "1",
"method": "call_tool",
"params": {
"name": "text_to_speech",
"arguments": {
"text": "Hello world",
"voice": "af_bella" // optional
}
}
}2.文本_语音_无选项
使用可自定义的参数将文本转换为语音。
{
"type": "request",
"id": "1",
"method": "call_tool",
"params": {
"name": "text_to_speech_with_options",
"arguments": {
"text": "Hello world",
"voice": "af_bella", // optional
"speed": 1.0, // optional (0.5 to 2.0)
}
}
}3.列表_语音
列出所有可用于文本转语音的语音。
{
"type": "request",
"id": "1",
"method": "list_voices",
"params": {}
}4.获取模式状态
检查TTS模型初始化的当前状态。这在首次启动服务器时特别有用,因为需要下载和初始化模型。
{
"type": "request",
"id": "1",
"method": "call_tool",
"params": {
"name": "get_model_status",
"arguments": {}
}
}响应示例:
{
"content": [{
"type": "text",
"text": "Model status: initializing (5s elapsed)"
}]
}可能的状态值:
uninitialized:模型初始化尚未开始initializing:正在下载和初始化模型ready:模型已准备好使用error:初始化过程中出错
测试
您可以使用MCP检查器或发送原始JSON消息来测试服务器:
# List available tools
echo '{"type":"request","id":"1","method":"list_tools","params":{}}' | node dist/index.js
# List available voices
echo '{"type":"request","id":"2","method":"list_voices","params":{}}' | node dist/index.js
# Convert text to speech
echo '{"type":"request","id":"3","method":"call_tool","params":{"name":"text_to_speech","arguments":{"text":"Hello world","voice":"af_bella"}}}' | node dist/index.js与Claude Desktop集成
要将此服务器与Claude Desktop一起使用,请将以下内容添加到您的Claude Desktop配置文件中(~/Library/Application Support/Claude/claude_desktop_config.json):
{
"servers": {
"speech": {
"command": "npx",
"args": ["@decodershq/speech-mcp-server"]
}
}
}贡献
欢迎投稿!请随时提交拉取请求。
许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
故障排除
模型初始化问题
服务器在启动时会自动尝试下载并初始化TTS模型。如果遇到初始化错误:
- 服务器将自动重试最多3次,每次尝试之间进行一次清理
- 使用
get_model_status用于监控初始化进度和任何错误的工具 - 如果所有重试后初始化失败,请尝试手动删除模型文件:
# Remove model files (MacOS/Linux)
rm -rf ~/.npm/_npx/**/node_modules/@huggingface/transformers/.cache/onnx-community/Kokoro-82M-v1.0-ONNX/onnx/model_quantized.onnx
rm -rf ~/.cache/huggingface/transformers/onnx-community/Kokoro-82M-v1.0-ONNX/onnx/model_quantized.onnx
# Then restart the server
npm start这 get_model_status 工具现在将在其响应中包含重试信息:
{
"content": [{
"type": "text",
"text": "Model status: initializing (5s elapsed, retry 1/3)"
}]
}