Skip to main content
Glama

generate_audio

Convert text prompts into speech or music audio files using the Pollinations API, returning downloadable URLs for generated content.

Instructions

Generate audio (speech or music) using Pollinations API. Returns a URL to the generated audio.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText for speech or music prompt
modelNoAudio modelelevenlabs
voiceNoVoice (elevenlabs only)nova

Implementation Reference

  • Handler function that executes the audio generation logic using the Pollinations API.
    export async function handleGenerateAudio(
      args: z.infer<typeof generateAudioSchema>
    ) {
      const model = getModel(args.model);
      if (!model || model.type !== "audio") {
        return {
          content: [
            {
              type: "text" as const,
              text: `Unknown audio model: ${args.model}. Use list_models to see available models.`,
            },
          ],
          isError: true,
        };
      }
      if (!API_KEY) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Audio models require a Pollinations API key. Set POLLINATIONS_API_KEY env variable.`,
            },
          ],
          isError: true,
        };
      }
    
      const params = new URLSearchParams({
        model: args.model,
      });
      if (args.model === "elevenlabs") {
        params.set("voice", args.voice);
      }
      if (API_KEY) params.set("token", API_KEY);
    
      const encodedPrompt = encodeURIComponent(args.prompt);
      const url = `https://gen.pollinations.ai/audio/${encodedPrompt}?${params}`;
    
      const info =
        args.model === "elevenlabs"
          ? `Voice: ${args.voice}`
          : "Type: Music generation";
    
      return {
        content: [
          {
            type: "text" as const,
            text: [
              `Audio generated successfully!`,
              `Model: ${model.name}`,
              info,
              `URL: ${url}`,
            ].join("\n"),
          },
        ],
      };
    }
  • Zod schema defining input validation for the generate_audio tool.
    export const generateAudioSchema = z.object({
      prompt: z.string().describe("Text for speech or music prompt"),
      model: z
        .enum(["elevenlabs", "elevenmusic"])
        .default("elevenlabs")
        .describe("Audio model"),
      voice: z
        .enum(["alloy", "echo", "fable", "onyx", "nova", "shimmer"])
        .default("nova")
        .describe("Voice (elevenlabs only)"),
    });

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/doctorm333/promptpilot-mcp-server'

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