venice_text_to_speech
Convert text to speech audio using Venice AI's TTS models and customizable voices for accessible audio content creation.
Instructions
Convert text to speech audio using Venice AI
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to convert to speech | |
| model | No | TTS model | tts-kokoro |
| voice | No | Voice ID (e.g., af_sky, af_bella, am_adam) | af_sky |
Implementation Reference
- src/tools/inference/index.ts:109-118 (handler)The main handler function that executes the text-to-speech logic by calling the Venice AI API, processing the audio response into base64, and formatting the output.
async ({ text, model, voice }) => { const response = await veniceAPI("/audio/speech", { method: "POST", body: JSON.stringify({ model, input: text, voice }) }); if (!response.ok) { const data = await response.json() as { error?: { message?: string } }; return { content: [{ type: "text" as const, text: `Error: ${data.error?.message || response.statusText}` }] }; } const arrayBuffer = await response.arrayBuffer(); const base64 = Buffer.from(arrayBuffer).toString("base64"); return { content: [{ type: "text" as const, text: `Audio generated (${Math.round(base64.length / 1024)}KB MP3): data:audio/mp3;base64,${base64.substring(0, 50)}...` }] }; } - src/tools/inference/index.ts:104-108 (schema)Zod schema defining the input parameters for the tool: text, optional model, and optional voice.
{ text: z.string().describe("Text to convert to speech"), model: z.string().optional().default("tts-kokoro").describe("TTS model"), voice: z.string().optional().default("af_sky").describe("Voice ID (e.g., af_sky, af_bella, am_adam)"), }, - src/tools/inference/index.ts:101-119 (registration)The server.tool() call that registers the venice_text_to_speech tool with its schema and handler.
server.tool( "venice_text_to_speech", "Convert text to speech audio using Venice AI", { text: z.string().describe("Text to convert to speech"), model: z.string().optional().default("tts-kokoro").describe("TTS model"), voice: z.string().optional().default("af_sky").describe("Voice ID (e.g., af_sky, af_bella, am_adam)"), }, async ({ text, model, voice }) => { const response = await veniceAPI("/audio/speech", { method: "POST", body: JSON.stringify({ model, input: text, voice }) }); if (!response.ok) { const data = await response.json() as { error?: { message?: string } }; return { content: [{ type: "text" as const, text: `Error: ${data.error?.message || response.statusText}` }] }; } const arrayBuffer = await response.arrayBuffer(); const base64 = Buffer.from(arrayBuffer).toString("base64"); return { content: [{ type: "text" as const, text: `Audio generated (${Math.round(base64.length / 1024)}KB MP3): data:audio/mp3;base64,${base64.substring(0, 50)}...` }] }; } );