get_random_unused_voice
Retrieve a random unused voice character from VOICEVOX to assign unique speakers for text-to-speech synthesis.
Instructions
使用されていない音声をランダムに1つ取得
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:242-276 (handler)Main handler implementation for 'get_random_unused_voice' tool. Gets all voices from VoiceVox, filters out voices currently in use, and randomly selects from unused voices (or all voices if all are in use)
case "get_random_unused_voice": { // 利用可能な全音声を取得 const allVoices = await voicevox.getVoices(); const voicesInUse = await queue.getVoicesInUse(); // 使用されていない音声を抽出 const unusedVoices = allVoices.filter( (voice) => !voicesInUse.includes(voice.id), ); let selectedVoice; if (unusedVoices.length > 0) { // 未使用の音声からランダムに選択 const randomIndex = Math.floor(Math.random() * unusedVoices.length); selectedVoice = unusedVoices[randomIndex]; } else { // 全ての音声が使用中の場合は、全音声からランダムに選択 const randomIndex = Math.floor(Math.random() * allVoices.length); selectedVoice = allVoices[randomIndex]; } return { content: [ { type: "text", text: JSON.stringify({ voice: selectedVoice, isUnused: unusedVoices.length > 0, totalVoices: allVoices.length, unusedCount: unusedVoices.length, }, null, 2), }, ], }; } - src/index.ts:122-129 (registration)Registration of 'get_random_unused_voice' tool with MCP server, defining tool name, description (in Japanese), and empty input schema
{ name: "get_random_unused_voice", description: "使用されていない音声をランダムに1つ取得", inputSchema: { type: "object", properties: {}, }, }, - src/voicevox.ts:15-30 (helper)Helper function that fetches all available voices from VOICEVOX API by querying /speakers endpoint and flattening speaker styles into voice objects
async getVoices(): Promise<Voice[]> { const response = await fetch(`${this.baseUrl}/speakers`); const speakers = await response.json() as any[]; const voices: Voice[] = []; for (const speaker of speakers) { for (const style of speaker.styles) { voices.push({ character: speaker.name, name: style.name, id: style.id, }); } } return voices; - src/queue.ts:73-81 (helper)Helper function that retrieves list of voice IDs currently in use across all processes via shared state
async getVoicesInUse(): Promise<number[]> { // 共有状態から全プロセスの使用中音声を取得 try { return await this.sharedState.getVoicesInUse(); } catch (error) { console.error("Failed to get voices in use:", error); // エラー時はローカルのキュー情報のみ返す const localVoices: number[] = []; if (this.currentTask) {