UNPKG

@chinchillaenterprises/mcp-ai-assistant

Version:

MCP server for AI assistant with ElevenLabs text-to-speech integration

63 lines 2.89 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.autoReadResponseTool = void 0; const zod_1 = require("zod"); const child_process_1 = require("child_process"); const util_1 = require("util"); const path_1 = __importDefault(require("path")); const execAsync = (0, util_1.promisify)(child_process_1.exec); const inputSchema = zod_1.z.object({ text: zod_1.z.string().describe('The full text response to read aloud'), voice: zod_1.z.string().optional().default('sarah').describe('Voice to use (sarah, aria, laura, charlie, george)'), autoPlay: zod_1.z.boolean().optional().default(true).describe('Automatically play the audio after generation') }); exports.autoReadResponseTool = { name: 'elevenlabs_auto_read_response', description: 'Automatically convert and read Claude\'s entire response using text-to-speech', inputSchema, handler: async (args) => { try { // Use the speak.js script in the dist directory // When compiled, __dirname points to dist/tools/tts/, so we go up to dist/ const scriptPath = path_1.default.join(__dirname, '../../speak.js'); // Escape quotes in the text for shell command const escapedText = args.text.replace(/"/g, '\\"').replace(/'/g, "\\'"); // Execute the speak command const command = `node "${scriptPath}" "${escapedText}" ${args.voice}`; const { stdout, stderr } = await execAsync(command); if (stderr && !stderr.includes('Playing audio')) { throw new Error(stderr); } // Extract the file path from stdout const filePathMatch = stdout.match(/Audio saved to: (.+\.mp3)/); const audioFile = filePathMatch ? filePathMatch[1] : 'audio file'; return { content: [{ type: 'text', text: JSON.stringify({ success: true, message: '🔊 Response is being read aloud', audioFile: audioFile, textLength: args.text.length, voice: args.voice }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : 'Failed to read response' }, null, 2) }] }; } } }; //# sourceMappingURL=auto-read-response.js.map