内容
MCP 服务器
文本转语音 MCP(模型上下文协议)服务器。采用适配器模式,支持多种 TTS 服务。
## 支持的 TTS 服务
- **Typecast** - [Neosapience](https://typecast.ai/) TTS API
## 安装
```bash
npm install
npm run build
```
## 环境变量
创建 `.env` 文件:
```env
TYPECAST_API_KEY=your_api_key_here
```
## 连接到 Claude Code
```bash
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` | 字符串 | 情感预设(`normal`、`happy`、`sad`等) |
| `emotion_intensity` | 数字 | 情感强度(0.0 ~ 2.0) |
| `volume` | 数字 | 音量(0 ~ 200,默认:100) |
| `pitch` | 数字 | 音调调节(-12 ~ 12) |
| `tempo` | 数字 | 节奏调节(0.5 ~ 2.0) |
| `format` | 字符串 | 输出格式(`mp3`或`wav`) |
| `outputDir` | 字符串 | 输出目录 |
| `outputName` | 字符串 | 输出文件名(不含扩展名) |
**响应:**
```json
{
"filePath": "/path/to/output.mp3",
"duration": 3.5,
"format": "mp3"
}
```
### `tts_list_voices`
查询可用的语音列表。
**参数:**
| 参数 | 必需 | 描述 |
|---------|:----:|------|
| `adapter` | ❌ | TTS 适配器(默认:`typecast`) |
| `model_id` | ❌ | 模型 ID |
**响应:**
```json
[
{
"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` 接口:
```typescript
// 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` 中注册适配器:
```typescript
import { MyTTSAdapter } from './adapters/my-tts.js';
const adapters: Record<string, TTSAdapter> = {
typecast: new TypecastAdapter(TYPECAST_API_KEY),
'my-tts': new MyTTSAdapter(API_KEY),
};
```
## 使用
```bash
pm