语音合成服务

一个支持多种TTS服务的语音合成服务器,提供文本转语音、语音列表查询等功能,适用于语音合成应用开发。

  • by inithink
  • JavaScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 inithink/tts-mcp

使用说明

TTS MCP服务器

Text-to-Speech模型上下文协议(MCP)服务器。通过适配器模式支持多种TTS服务。

支持TTS服务

  • 让总演同一类型的角色 - 新智慧 TTS API

安装

npm install
npm run build

环境变量

.env 创建文件:

TYPECAST_API_KEY=your_api_key_here

连接到Claude Code

claude mcp add tts-mcp -t stdio -s user \
  -e TYPECAST_API_KEY=your_api_key \
  -- node /path/to/tts-mcp/dist/index.js

“工具”(Tools)

tts_synthesize

将文本转换为语音文件。

参数:

参数 必需 说明
text 要语音的文本
voice_id 语音ID(例如: tc_xxx)
model_id 型号ID(默认: ssfm-v21)
adapter TTS适配器(默认: typecast)
options 其他选项(请参阅下文)

选项:

选项 类型 说明
emotion string 情感预设(normal, happy, sad 等)
emotion_intensity number 情感强度(0.0~2.0)
volume number 卷(0到200,默认值:100)
pitch 调整音调(-12-12)
tempo 调整速度(0.5~2.0)
format string 输出格式(mp3 或者 wav)
outputDir string 输出目录
outputName 输出文件名(不包括扩展名)

答复:

{
  "filePath": "/path/to/output.mp3",
  "duration": 3.5,
  "format": "mp3"
}

tts_list_voices

查看可用语音列表。

参数:

参数 必需 说明
adapter TTS适配器(默认: typecast)
model_id 型号ID

答复:

[
  {
    "id": "tc_xxx",
    "name": "Voice Name",
    "model": "ssfm-v21",
    "emotions": ["normal", "happy", "sad"]
  }
]

使用示例

在Claude Code中使用

# 음성 목록 조회
"typecast에서 사용 가능한 음성 목록 보여줘"

# TTS 생성
"'안녕하세요'를 tc_xxx 음성으로 변환해줘"

# 옵션 포함
"'반갑습니다'를 happy 감정으로, tempo 1.2로 변환해서 /output 폴더에 저장해줘"

适配器扩展

添加新TTS服务的步骤 TTSAdapter 实现界面:

// src/adapters/my-tts.ts
import type { TTSAdapter, TTSOptions, TTSResult, Voice } from './base.js';

export class MyTTSAdapter implements TTSAdapter {
  readonly name = 'my-tts';

  async synthesize(
    text: string,
    voiceId: string,
    modelId: string,
    options?: TTSOptions
  ): Promise<TTSResult> {
    // 구현
  }

  async getVoices(modelId?: string): Promise<Voice[]> {
    // 구현
  }
}

而且 src/index.ts在中注册适配器:

import { MyTTSAdapter } from './adapters/my-tts.js';

const adapters: Record<string, TTSAdapter> = {
  typecast: new TypecastAdapter(TYPECAST_API_KEY),
  'my-tts': new MyTTSAdapter(API_KEY),
};

作为PM2运行

pm2 start ecosystem.config.cjs

许可证

麻省理工学院