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
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | Text for speech or music prompt | |
| model | No | Audio model | elevenlabs |
| voice | No | Voice (elevenlabs only) | nova |
Implementation Reference
- src/tools.ts:270-326 (handler)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"), }, ], }; } - src/tools.ts:77-87 (schema)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)"), });