get_session_voice
Retrieve your current session's assigned voice character to identify the active VOICEVOX speaker for text-to-speech synthesis.
Instructions
このセッションで使用する音声を取得(セッション毎に固定)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:278-307 (handler)Tool handler for 'get_session_voice' - handles the tool call, invokes sessionVoice.getSessionVoice(), and returns the voice information with session metadata
case "get_session_voice": { try { const sessionInfo = await sessionVoice.getSessionVoice(); const voices = await voicevox.getVoices(); const selectedVoice = voices.find((v) => v.id === sessionInfo.voiceId); return { content: [ { type: "text", text: JSON.stringify({ voice: selectedVoice, sessionInfo: sessionInfo.sessionInfo, }, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `エラー: ${ error instanceof Error ? error.message : "不明なエラー" }`, }, ], }; } } - src/session-voice.ts:42-60 (handler)Core implementation of getSessionVoice() - initializes session voice and returns voice ID with session metadata (start time, duration, client ID)
async getSessionVoice(): Promise<{ voiceId: number; sessionInfo: { startTime: number; durationMs: number; clientId: string; }; }> { const voiceId = await this.initializeSession(); return { voiceId, sessionInfo: { startTime: this.sessionStartTime, durationMs: Date.now() - this.sessionStartTime, clientId: this.sharedState.getClientId(), }, }; } - src/index.ts:130-137 (registration)Tool registration for 'get_session_voice' - defines the tool name, description, and empty input schema in the tools list
{ name: "get_session_voice", description: "このセッションで使用する音声を取得(セッション毎に固定)", inputSchema: { type: "object", properties: {}, }, }, - src/session-voice.ts:17-40 (helper)Helper method initializeSession() - selects and registers a voice for the session using SharedStateManager, falls back to default voice on error
async initializeSession(): Promise<number> { if (this.sessionVoiceId !== undefined) { return this.sessionVoiceId; } try { // 利用可能な全音声を取得 const allVoices = await this.voicevox.getVoices(); const availableVoiceIds = allVoices.map((voice) => voice.id); // 音声の選択と登録をアトミックに実行 this.sessionVoiceId = await this.sharedState.selectAndRegisterVoice( availableVoiceIds, this.defaultVoiceId, ); return this.sessionVoiceId; } catch (error) { console.error("Failed to initialize session voice:", error); // エラー時はデフォルト音声を使用 this.sessionVoiceId = this.defaultVoiceId; return this.sessionVoiceId; } }