text_to_speech_with_options
Convert text to speech with customizable voice selection and adjustable speech speed using the Kokoro TTS model.
Instructions
Convert text to speech with customizable speed
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"text": "<text>"
},
"name": "text_to_speech_with_options"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The text to convert to speech | |
| voice | No | The voice to use for speech synthesis (e.g. 'af_bella'). Use list_voices to see available options. | |
| speed | No | Speech rate multiplier (0.5 to 2.0) |
Implementation Reference
- src/index.ts:294-307 (handler)Handler logic for executing the text_to_speech_with_options tool. Extracts arguments and delegates to TTSClient.generateAndPlayAudio method.
case "text_to_speech_with_options": { const args = request.params.arguments as unknown as TextToSpeechWithOptionsArgs; if (!args.text) { throw new Error("Missing required argument: text"); } await ttsClient.generateAndPlayAudio(args.text, args.voice, args.speed); return { content: [{ type: "text", text: `Successfully generated and played audio${args.voice ? ` using voice: ${args.voice}` : ''} (speed: ${args.speed || 1.0})` }], }; } - src/index.ts:61-86 (schema)Tool definition including name, description, and input schema for validation.
const textToSpeechWithOptionsTool: Tool = { name: "text_to_speech_with_options", description: "Convert text to speech with customizable speed", inputSchema: { type: "object", properties: { text: { type: "string", description: "The text to convert to speech", minLength: 1, maxLength: 1000, }, voice: { type: "string", description: "The voice to use for speech synthesis (e.g. 'af_bella'). Use list_voices to see available options.", }, speed: { type: "number", description: "Speech rate multiplier (0.5 to 2.0)", minimum: 0.5, maximum: 2.0, }, }, required: ["text"], }, }; - src/index.ts:34-37 (schema)TypeScript interface defining the expected arguments for the tool.
interface TextToSpeechWithOptionsArgs extends TextToSpeechArgs { speed?: number; voice?: KokoroVoice; } - src/index.ts:356-360 (registration)Registers the textToSpeechWithOptionsTool in the list returned by ListToolsRequest handler.
textToSpeechTool, textToSpeechWithOptionsTool, listVoicesTool, getModelStatusTool, ], - src/index.ts:230-250 (helper)Core helper method in TTSClient that performs the actual text-to-speech generation and playback using KokoroTTS.
async generateAndPlayAudio(text: string, voice?: KokoroVoice, speed?: number): Promise<void> { await this.waitForInit(); if (!this.ttsInstance) { throw new Error("TTS model not initialized"); } const audio = await this.ttsInstance.generate(text, { voice: voice || DEFAULT_VOICE, // @ts-ignore-line speed: speed || DEFAULT_SPEECH_SPEED, }); const tempFile = join(tmpdir(), `${Date.now()}.wav`); await audio.save(tempFile); await player.play({ path: tempFile, sync: true }); } }