mcp_openai_tts
Convert text to speech using OpenAI TTS API. Generates audio files, returns their paths, and ensures users receive the output for further use.
Instructions
OpenAI TTS API를 사용하여 텍스트를 음성으로 변환합니다. 생성된 오디오 파일 경로를 반환하며, 이 경로는 반드시 사용자에게 알려주어야 합니다.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fileName | No | 저장할 파일 이름 (확장자 제외) | |
| model | No | 사용할 모델 (예: tts-1, tts-1-hd) | |
| saveDir | No | 음성 파일을 저장할 디렉토리 | |
| speed | No | 음성 속도(0.25-4.0) | |
| text | Yes | 음성으로 변환할 텍스트 | |
| voice | No | 음성 종류 |
Input Schema (JSON Schema)
{
"properties": {
"fileName": {
"description": "저장할 파일 이름 (확장자 제외)",
"type": "string"
},
"model": {
"description": "사용할 모델 (예: tts-1, tts-1-hd)",
"type": "string"
},
"saveDir": {
"description": "음성 파일을 저장할 디렉토리",
"type": "string"
},
"speed": {
"description": "음성 속도(0.25-4.0)",
"maximum": 4,
"minimum": 0.25,
"type": "number"
},
"text": {
"description": "음성으로 변환할 텍스트",
"type": "string"
},
"voice": {
"description": "음성 종류",
"enum": [
"alloy",
"echo",
"fable",
"onyx",
"nova",
"shimmer"
],
"type": "string"
}
},
"required": [
"text"
],
"type": "object"
}
Implementation Reference
- src/services/openai-service.ts:174-250 (handler)Core handler logic for OpenAI TTS: sends POST to /audio/speech endpoint, receives MP3 audio data, saves to file with timestamp, returns JSON with file path and size./** * TTS API를 사용하여 텍스트를 음성으로 변환합니다 */ async textToSpeech(args: { text: string; model?: string; voice?: string; speed?: number; saveDir?: string; fileName?: string; }): Promise<string> { try { if (!OPENAI_API_KEY) { throw new McpError( ErrorCode.InternalError, 'OPENAI_API_KEY가 설정되지 않았습니다.' ); } const response = await axios.post( `${OPENAI_API_BASE}/audio/speech`, { model: args.model || 'tts-1', input: args.text, voice: args.voice || 'alloy', // alloy, echo, fable, onyx, nova, shimmer speed: args.speed || 1.0, response_format: 'mp3' }, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${OPENAI_API_KEY}` }, responseType: 'arraybuffer' } ); // 음성 파일 저장 const saveDir = args.saveDir || DEFAULT_SAVE_DIR; await this.ensureDirectoryExists(saveDir); const timestamp = Date.now(); const fileName = args.fileName ? `${args.fileName}.mp3` : `tts_${timestamp}.mp3`; const filePath = path.join(saveDir, fileName); await writeFileAsync(filePath, Buffer.from(response.data)); return JSON.stringify({ audio_file: filePath, size_bytes: response.data.length, message: `음성 파일이 ${filePath}에 저장되었습니다.` }, null, 2); } catch (error) { if (axios.isAxiosError(error)) { const statusCode = error.response?.status; let errorMessage = error.message; try { // 응답이 arraybuffer일 경우 처리 if (error.response?.data instanceof ArrayBuffer) { const text = Buffer.from(error.response.data).toString('utf8'); const json = JSON.parse(text); errorMessage = json.error?.message || errorMessage; } } catch (e) { // 파싱 오류는 무시 } throw new McpError( ErrorCode.InternalError, `OpenAI API 오류 (${statusCode}): ${errorMessage}` ); } throw new McpError(ErrorCode.InternalError, `음성 변환 요청 실패: ${formatError(error)}`); } }
- src/tools/index.ts:662-716 (handler)MCP tool object definition for 'mcp_openai_tts' with input schema and wrapper handler that calls the OpenAI service and formats ToolResponse.{ name: 'mcp_openai_tts', description: 'OpenAI TTS API를 사용하여 텍스트를 음성으로 변환합니다. 생성된 오디오 파일 경로를 반환하며, 이 경로는 반드시 사용자에게 알려주어야 합니다.', inputSchema: { type: 'object', properties: { text: { type: 'string', description: '음성으로 변환할 텍스트' }, model: { type: 'string', description: '사용할 모델 (예: tts-1, tts-1-hd)' }, voice: { type: 'string', description: '음성 종류', enum: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] }, speed: { type: 'number', description: '음성 속도(0.25-4.0)', minimum: 0.25, maximum: 4.0 }, saveDir: { type: 'string', description: '음성 파일을 저장할 디렉토리' }, fileName: { type: 'string', description: '저장할 파일 이름 (확장자 제외)' } }, required: ['text'] }, async handler(args: any): Promise<ToolResponse> { try { const result = await openaiService.textToSpeech(args); return { content: [{ type: 'text', text: result }] }; } catch (error) { return { content: [{ type: 'text', text: `OpenAI TTS 오류: ${error instanceof Error ? error.message : String(error)}` }] }; } } },
- src/tools/index.ts:665-697 (schema)JSON schema defining input parameters for the mcp_openai_tts tool, requiring 'text' and supporting model, voice, speed, saveDir, fileName.inputSchema: { type: 'object', properties: { text: { type: 'string', description: '음성으로 변환할 텍스트' }, model: { type: 'string', description: '사용할 모델 (예: tts-1, tts-1-hd)' }, voice: { type: 'string', description: '음성 종류', enum: ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'] }, speed: { type: 'number', description: '음성 속도(0.25-4.0)', minimum: 0.25, maximum: 4.0 }, saveDir: { type: 'string', description: '음성 파일을 저장할 디렉토리' }, fileName: { type: 'string', description: '저장할 파일 이름 (확장자 제외)' } }, required: ['text'] },
- src/index.ts:25-54 (registration)MCP server capabilities registration enabling the mcp_openai_tts tool (set to true).tools: { mcp_sparql_execute_query: true, mcp_sparql_update: true, mcp_sparql_list_repositories: true, mcp_sparql_list_graphs: true, mcp_sparql_get_resource_info: true, mcp_ollama_run: true, mcp_ollama_show: true, mcp_ollama_pull: true, mcp_ollama_list: true, mcp_ollama_rm: true, mcp_ollama_chat_completion: true, mcp_ollama_status: true, mcp_http_request: true, mcp_openai_chat: true, mcp_openai_image: true, mcp_openai_tts: true, mcp_openai_transcribe: true, mcp_openai_embedding: true, mcp_gemini_generate_text: true, mcp_gemini_chat_completion: true, mcp_gemini_list_models: true, mcp_gemini_generate_images: false, mcp_gemini_generate_image: false, mcp_gemini_generate_videos: false, mcp_gemini_generate_multimodal_content: false, mcp_imagen_generate: false, mcp_gemini_create_image: false, mcp_gemini_edit_image: false },