voicevox
Synthesize and playback speech using a text-to-speech engine compatible with VOICEVOX, enabling AI agents to generate natural voice output for applications.
Instructions
VOICEVOXを使用して音声を合成し、ホストコンピュータで再生します
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "voicevox"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | No | 合成する文章 |
Implementation Reference
- src/tools/VoicevoxTool.ts:32-68 (handler)The execute method that implements the core voicevox tool logic: creates audio query via VOICEVOX API, synthesizes speech, saves to temporary WAV file, and plays it on the host using platform-specific playback.
async execute({ text }: VoicevoxInput): Promise<string> { try { // 音声合成用のクエリを作成 const queryResponse = await axios.post( `${this.VOICEVOX_API_URL}/audio_query`, null, { params: { text, speaker: this.VOICEVOX_API_SPEAKER_ID } } ); // 音声を合成 const synthesisResponse = await axios.post( `${this.VOICEVOX_API_URL}/synthesis`, queryResponse.data, { params: { speaker: this.VOICEVOX_API_SPEAKER_ID }, responseType: "arraybuffer", } ); // 音声データを一時ファイルに保存 fs.writeFileSync( this.TEMP_AUDIO_FILE, Buffer.from(synthesisResponse.data) ); // 音声を再生 await this.playAudio(this.TEMP_AUDIO_FILE); return `「${text}」の音声をホストコンピュータで再生しました。話者ID: ${this.VOICEVOX_API_SPEAKER_ID}`; } catch (error) { console.log(error); if (error instanceof Error) { throw new Error(`音声合成または再生に失敗しました: ${error.message}`); } throw new Error("音声合成または再生に失敗しました"); } } - src/tools/VoicevoxTool.ts:12-26 (schema)Input schema definition using Zod for validation and TypeScript interface for typing the 'text' parameter expected by the voicevox tool.
interface VoicevoxInput { text: string; } class VoicevoxTool extends MCPTool<VoicevoxInput> { name = "voicevox"; description = "VOICEVOXを使用して音声を合成し、ホストコンピュータで再生します"; schema = { text: { type: z.string(), description: "合成する文章", }, }; - src/tools/VoicevoxTool.ts:70-92 (helper)Supporting helper method to play the generated audio file using OS-specific commands: VLC on Windows, aplay on Linux.
private async playAudio(filePath: string): Promise<void> { try { switch (process.platform) { // Windows case "win32": await execAsync( `vlc.exe -I dummy --dummy-quiet ${filePath} vlc://quit` ); break; // Linux or Docker case "linux": await execAsync(`aplay ${filePath}`); break; // Mac case "darwin": default: throw new Error("サポートされていないOSです"); } } catch (error) { throw new Error(`音声の再生に失敗しました: ${error}`); } } }