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-types.json 将可读名称映射到官方 voice_type
  • 简单集成:暴露 MCP 工具,Agent 直接调用生成 WAV 文件
  • 跨平台运行:Windows、Linux、macOS

🚀 安装

使用 uvx(推荐)

uvx mcp-bytedance-tts@latest  # 直接运行、更新,无需安装

或者使用 pipx 安装:

pipx install mcp-bytedance-tts

使用 uvx 运行(推荐)

uvx mcp-bytedance-tts

构建和发布

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-types.json,将“可读名称”映射到“官方 voice_type ID”。当调用时传入名称会自动解析为 ID。

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

🖥️ MCP 客户端配置

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

使用 uvx(推荐)

{
  "mcpServers": {
    "mcp-bytedance-tts": {
      "command": "uvx",
      "args": ["mcp-bytedance-tts"]
    }
  }
}

🛠️ 可用工具

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

⚡ 快速开始

uvx mcp-bytedance-tts

💡 使用示例

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

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

音色映射

音色名称到 ID 的映射关系存储在 voice-types.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
│       └── config.json
├── voice-types.json
├── pyproject.toml
├── requirements.txt
├── README.md
├── APIDOC.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.7.tar.gz (9.0 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.7-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp_bytedance_tts-1.0.7.tar.gz
  • Upload date:
  • Size: 9.0 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.7.tar.gz
Algorithm Hash digest
SHA256 99e804ac7cb62688f4da3d3cf17b92c79f1d8f883d432d79979a319b2ff77fcf
MD5 fcf517a4b5ccf766d597e7536f28fa53
BLAKE2b-256 6b7124fbff03a3e5705350c70b90060b4323965402d13735ad333a69ba7c7edd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_bytedance_tts-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d7679022fade3cd35d9fa7b639da08d239ee5a683b49bd390020bec40fd881e1
MD5 3adb4848bcc8e2dbd31015c5f9cb0b0f
BLAKE2b-256 4183af8a0c0f805c83df4fe7ca05aeaa6d7e1b561bf45dc9a1f0300b5606359b

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