Skip to main content

MCP server for text-to-speech using bytedance-tts - generates audio from text

Project description

MCP Bytedance TTS 语音生成器

本项目是一个 Model Context Protocol (MCP) 服务器,基于字节跳动 OpenSpeech TTS 的 HTTP 接口,将文本生成语音音频。 遵循“只使用 HTTP,不使用 WebSocket”的约定。

✨ 功能特性

  • 文本转语音:调用 Bytedance OpenSpeech TTS HTTP 接口生成音频
  • 音色管理:支持通过 voice-config.json 将可读名称映射到官方 voice_type
  • 简单集成:暴露 MCP 工具,Agent 直接调用生成 WAV 文件
  • 跨平台运行:Windows、Linux、macOS

🚀 安装

使用虚拟环境(推荐)

python -m venv .venv
.venv/Scripts/python.exe -m pip install -U pip
.venv/Scripts/pip.exe install -r requirements.txt

从源码运行

git clone https://github.com/aardpro/mcp-bytedance-tts.git
cd mcp-bytedance-tts
.venv/Scripts/python.exe -m main

构建和发布

rm -rf dist && pip install build && python -m build && pip install twine && twine upload dist/*

⚙️ 配置

config.json 中填写以下字段:

  • appid:控制台获取的应用 ID
  • accessToken:控制台获取的访问令牌(用于 Authorization)
  • secretKey:控制台获取的密钥(当前 HTTP 方案不直接使用)
  • defaultVoiceType:默认的 voice_type(如 zh_male_xxx)
  • defaultAudioEncoding:音频编码(默认 wav)
  • uid:用户标识

可选在项目 src/ 目录放置 voice-config.json,将“可读名称”映射到“官方 voice_type ID”。当调用时传入名称会自动解析为 ID。

安全提示:请勿将密钥、令牌提交到版本库。

🖥️ MCP 客户端配置

在 MCP 客户端(例如 Claude Desktop、Cursor)的配置中添加:

选项 1:跨平台

{
  "mcpServers": {
    "McpBytedanceTTS": {
      "command": "python",
      "args": ["-m", "main"]
    }
  }
}

选项 2:Windows(确保 UTF-8 编码)

{
  "mcpServers": {
    "McpBytedanceTTS": {
      "command": "cmd",
      "args": [
        "/c",
        "chcp 65001 >nul && python -m main"
      ]
    }
  }
}

🛠️ 可用工具

mcp_bytedance_tts_generate_audio

使用字节跳动 OpenSpeech TTS 的 HTTP 接口(仅 HTTP)将文本生成音频文件。

参数

  • text(string,必填):要转换为语音的文本
  • voiceType(string,可选):音色名称或 voice_type ID;未提供时使用 defaultVoiceType
  • outputDir(string,必填):输出目录
{
  "name": "mcp_bytedance_tts_generate_audio",
  "arguments": {
    "text": "请将这段文字合成为语音文件",
    "voiceType": "zh_male_yuanboxiaoshu_moon_bigtts",
    "outputDir": "./output"
  }
}

返回值

  • 文本:生成成功消息,包含最终 WAV 文件路径(例如 ./output/1767514828_93829.wav)

工具定义位置:server.py

⚡ 快速开始

python -m venv .venv
.venv/Scripts/python.exe -m pip install -U pip
.venv/Scripts/pip.exe install -r requirements.txt
.venv/Scripts/python.exe -m main

💡 使用示例

配置完成后,你可以直接让 AI 助手:

  • "将这段中文生成音频文件"
  • "指定音色 温柔女神 生成语音"
  • "把文本生成 WAV 并保存到 ./output"

音色映射

音色名称到 ID 的映射关系存储在 voice-config.json 中。 例如,"温柔女神" 映射到 "ICL_zh_female_wenrounvshen_239eff5e8ffa_tob"。

💻 开发

设置开发环境

git clone https://github.com/aardpro/mcp-bytedance-tts.git
cd mcp-bytedance-tts
pip install -e ".[dev]"

运行测试

pytest

📂 项目结构

mcp-bytedance-tts/
├── src/
│   └── main/
│       ├── __init__.py
│       ├── __main__.py
│       └── server.py
├── pyproject.toml
├── README.md
└── LICENSE

❓ 常见问题

配置问题

请确保已正确填写 config.json 的 appid 与 accessToken,并设置 defaultVoiceType。

音频生成失败

如果音频生成失败,请检查:

  1. appid 与 accessToken 是否有效
  2. voiceType 是否存在或映射正确
  3. outputDir 是否有写入权限

📄 许可证

MIT License - 详见 LICENSE 文件。

🤝 贡献

欢迎提交 Pull Request 来改进这个项目!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_bytedance_tts-1.0.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_bytedance_tts-1.0.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file mcp_bytedance_tts-1.0.1.tar.gz.

File metadata

  • Download URL: mcp_bytedance_tts-1.0.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mcp_bytedance_tts-1.0.1.tar.gz
Algorithm Hash digest
SHA256 89a783f26619ceec27278306a32320afe01e7062742c88590f27c0dfe0aaf099
MD5 61998265a76b8ccdfc3c914089555ae9
BLAKE2b-256 652837e1b51a41a91a4114d0c8fa372c5609e5222abb0b4bf821fcab97ae6af6

See more details on using hashes here.

File details

Details for the file mcp_bytedance_tts-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_bytedance_tts-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b1ff8d914125b0791a082e612379b29d2a0600a990f92164ef3ed981c58c2ecf
MD5 b1a226911e206a556fc35bf89463cb3e
BLAKE2b-256 91d7a80785123ad1d0e982fa1fb610a93d1b137ae3d143156b45bdf2eae146e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page