Skip to main content
Glama

text_to_speech

Convert written text into spoken audio via system output using customizable voice options. Ideal for accessibility, automation, or learning applications.

Instructions

Convert text to speech and play it through system audio

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe text to convert to speech
voiceNoThe voice to use for speech synthesis (e.g. 'af_bella'). Use list_voices to see available options.

Implementation Reference

  • Core handler function that generates speech audio using KokoroTTS, saves to temp WAV file, and plays it via node-wav-player. Called by text_to_speech tool.
    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 }); } }
  • Tool dispatch handler case for 'text_to_speech': validates args and invokes the generateAndPlayAudio method.
    case "text_to_speech": { const args = request.params.arguments as unknown as TextToSpeechArgs; if (!args.text) { throw new Error("Missing required argument: text"); } await ttsClient.generateAndPlayAudio(args.text, args.voice); return { content: [{ type: "text", text: `Successfully generated and played audio${args.voice ? ` using voice: ${args.voice}` : ''}` }], }; }
  • Defines the text_to_speech tool schema: input validation for 'text' (required) and optional 'voice'.
    const textToSpeechTool: Tool = { name: "text_to_speech", description: "Convert text to speech and play it through system audio", 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.", }, }, required: ["text"], }, };
  • TypeScript interface defining arguments for text_to_speech tool.
    interface TextToSpeechArgs { text: string; voice?: KokoroVoice; }
  • src/index.ts:355-360 (registration)
    Registers the text_to_speech tool (as textToSpeechTool) in the ListTools response.
    tools: [ textToSpeechTool, textToSpeechWithOptionsTool, listVoicesTool, getModelStatusTool, ],

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hammeiam/koroko-speech-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server