tts
Convert text to speech audio with optional voice description. Generate spoken output from written text.
Instructions
Convert text to speech audio. Cost: 2 credits.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to convert to speech | |
| voice_description | No | Describe the voice, e.g. 'calm professional female' |
Implementation Reference
- src/index.ts:82-89 (schema)Schema definition for the 'tts' tool: defines name, description, and inputSchema with 'text' (required) and 'voice_description' (optional) parameters.
{ name: "tts", description: "Convert text to speech audio. Cost: 2 credits.", inputSchema: { text: z.string().describe("Text to convert to speech"), voice_description: z.string().optional().describe("Describe the voice, e.g. 'calm professional female'"), }, }, - src/index.ts:246-259 (registration)Registration of all capabilities (including 'tts') as MCP tools via server.registerTool() in a loop. The handler delegates to the generic callSuprsonic() function.
// Register each capability as an MCP tool for (const cap of CAPABILITIES) { // Cast inputSchema to avoid TS2589 (excessively deep type instantiation from Zod chains) server.registerTool( cap.name, { description: cap.description, inputSchema: cap.inputSchema as any, }, async (args: any): Promise<CallToolResult> => { return callSuprsonic(cap.name, args as Record<string, unknown>); }, ); } - src/index.ts:183-234 (handler)Generic handler function callSuprsonic() that executes all tool logic by calling the Suprsonic REST API (/v1/agent). The 'tts' tool name is passed as the 'capability' parameter along with its arguments.
async function callSuprsonic(capability: string, params: Record<string, unknown>): Promise<CallToolResult> { if (!API_KEY) { return { content: [{ type: "text", text: "Error: SUPRSONIC_API_KEY environment variable is not set. Get your key at https://suprsonic.ai/app/apis" }], isError: true, }; } try { const resp = await fetch(`${BASE_URL}/v1/agent`, { method: "POST", headers: { "Authorization": `Bearer ${API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ capability, params }), }); const result = await resp.json() as any; // Handle non-envelope responses (401, 429, etc. return {"detail": ...}) if (result.detail && result.success === undefined) { const msg = typeof result.detail === "object" ? (result.detail.title || result.detail.detail || JSON.stringify(result.detail)) : String(result.detail); return { content: [{ type: "text", text: `Error (HTTP ${resp.status}): ${msg}` }], isError: true, }; } if (!result.success) { const errMsg = result.error?.detail || result.error?.title || "Request failed"; return { content: [{ type: "text", text: `Error: ${errMsg}` }], isError: true, }; } const text = JSON.stringify(result.data, null, 2); const meta = result.metadata ? `\n\n[Provider: ${(result.metadata as any).provider_used || "unknown"}, ${(result.metadata as any).response_time_ms || 0}ms, ${result.credits_used || 0} credits]` : ""; return { content: [{ type: "text", text: text + meta }], }; } catch (err) { return { content: [{ type: "text", text: `Network error: ${err instanceof Error ? err.message : String(err)}` }], isError: true, }; } } - src/index.ts:30-34 (helper)The CapabilityDef interface that defines the shape used for all tool definitions including 'tts'.
interface CapabilityDef { name: string; description: string; inputSchema: Record<string, z.ZodType>; }