Skip to main content
Glama

sayText

Convert written text into spoken audio by generating speech verbatim. Customize voice, format, and tone for tailored audio output. Ideal for creating voiceovers, accessibility tools, or personalized audio content.

Instructions

Generate speech that says the provided text verbatim

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoFormat of the audio (mp3, wav, etc.)
textYesThe text to speak verbatim
voiceNoVoice to use for audio generation (default: "alloy")
voiceInstructionsNoAdditional instructions for voice character/style (e.g., "Speak with enthusiasm" or "Use a calm tone")

Implementation Reference

  • The handler function that implements the sayText tool. It takes text input, optional voice/format/voiceInstructions/audioPlayer/tempDir, generates audio via Pollinations API with verbatim prompt, converts to base64, optionally plays it, and returns MCP response with audio and text content.
    async function sayText(params) { const { text, voice = "alloy", format = "mp3", voiceInstructions, audioPlayer, tempDir, } = params; if (!text || typeof text !== "string") { throw new Error("Text is required and must be a string"); } // Prepare the query parameters const queryParams = { model: "openai-audio", voice, format, }; // Prepare the prompt with the verbatim instruction let finalPrompt = `Say verbatim: ${text}`; // Add voice instructions if provided if (voiceInstructions) { finalPrompt = `${voiceInstructions}\n\n${finalPrompt}`; } // Build the URL using the utility function const url = buildUrl( AUDIO_API_BASE_URL, encodeURIComponent(finalPrompt), queryParams, ); try { // Fetch the audio from the URL const response = await fetch(url); if (!response.ok) { throw new Error( `Failed to generate speech: ${response.statusText}`, ); } // Get the audio data as an ArrayBuffer const audioBuffer = await response.arrayBuffer(); // Convert the ArrayBuffer to a base64 string const base64Data = Buffer.from(audioBuffer).toString("base64"); // Determine the mime type from the format const mimeType = `audio/${format === "mp3" ? "mpeg" : format}`; // Play the audio if an audio player is provided if (audioPlayer) { const tempDirPath = tempDir || os.tmpdir(); await playAudio( base64Data, mimeType, "say_text", audioPlayer, tempDirPath, ); } // Return the response in MCP format return createMCPResponse([ { type: "audio", data: base64Data, mimeType, }, createTextContent( `Generated audio for text: "${text}"\n\nVoice: ${voice}\nFormat: ${format}`, ), ]); } catch (error) { console.error("Error generating audio:", error); throw error; } }
  • Registration of the sayText tool within the audioTools export array. Includes tool name, description, Zod input schema, and reference to the sayText handler function.
    "sayText", "Generate speech that says the provided text verbatim", { text: z.string().describe("The text to speak verbatim"), voice: z .string() .optional() .describe( 'Voice to use for audio generation (default: "alloy")', ), format: z .string() .optional() .describe("Format of the audio (mp3, wav, etc.)"), voiceInstructions: z .string() .optional() .describe( 'Additional instructions for voice character/style (e.g., "Speak with enthusiasm" or "Use a calm tone")', ), }, sayText, ],
  • Zod schema defining the input parameters for the sayText tool: required 'text', optional 'voice', 'format', 'voiceInstructions'.
    text: z.string().describe("The text to speak verbatim"), voice: z .string() .optional() .describe( 'Voice to use for audio generation (default: "alloy")', ), format: z .string() .optional() .describe("Format of the audio (mp3, wav, etc.)"), voiceInstructions: z .string() .optional() .describe( 'Additional instructions for voice character/style (e.g., "Speak with enthusiasm" or "Use a calm tone")', ), },

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/tusharpatil2912/pollinations-mcp'

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