@chinchillaenterprises/mcp-ai-assistant
Version:
MCP server for AI assistant with ElevenLabs text-to-speech integration
84 lines • 3.84 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.textToSpeechTool = void 0;
const zod_1 = require("zod");
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const account_state_js_1 = require("../../services/account-state.js");
const elevenlabs_client_js_1 = require("../../services/elevenlabs-client.js");
const inputSchema = zod_1.z.object({
text: zod_1.z.string().describe('The text to convert to speech'),
voiceId: zod_1.z.string().describe('The ID of the voice to use'),
outputPath: zod_1.z.string().describe('The file path where the audio will be saved'),
modelId: zod_1.z.string().optional().describe('The ID of the model to use (default: eleven_monolingual_v1)'),
stability: zod_1.z.number().min(0).max(1).optional().describe('Voice stability (0-1, default: 0.5)'),
similarityBoost: zod_1.z.number().min(0).max(1).optional().describe('Voice similarity boost (0-1, default: 0.5)'),
style: zod_1.z.number().min(0).max(1).optional().describe('Voice style (0-1, for compatible models)'),
useSpeakerBoost: zod_1.z.boolean().optional().describe('Enable speaker boost (for compatible models)'),
outputFormat: zod_1.z.enum([
'mp3_44100_32',
'mp3_44100_64',
'mp3_44100_96',
'mp3_44100_128',
'mp3_44100_192',
'pcm_16000',
'pcm_22050',
'pcm_24000',
'pcm_44100',
'ulaw_8000'
]).optional().describe('Audio output format (default: mp3_44100_128)'),
optimizeStreamingLatency: zod_1.z.number().min(0).max(4).optional().describe('Streaming latency optimization (0-4)')
});
exports.textToSpeechTool = {
name: 'elevenlabs_text_to_speech',
description: 'Convert text to speech using ElevenLabs API and save to file',
inputSchema,
handler: async (args) => {
const accountState = new account_state_js_1.AccountState();
const client = new elevenlabs_client_js_1.ElevenLabsClient(accountState);
const options = {
modelId: args.modelId,
voiceSettings: {
stability: args.stability ?? 0.5,
similarity_boost: args.similarityBoost ?? 0.5,
style: args.style,
use_speaker_boost: args.useSpeakerBoost
},
outputFormat: args.outputFormat,
optimizeStreamingLatency: args.optimizeStreamingLatency
};
try {
const audioBuffer = await client.textToSpeech(args.text, args.voiceId, options);
const outputDir = path_1.default.dirname(args.outputPath);
await fs_1.promises.mkdir(outputDir, { recursive: true });
await fs_1.promises.writeFile(args.outputPath, audioBuffer);
return {
content: [{
type: 'text',
text: JSON.stringify({
success: true,
outputPath: args.outputPath,
fileSize: audioBuffer.length,
format: args.outputFormat || 'mp3_44100_128',
textLength: args.text.length
}, null, 2)
}]
};
}
catch (error) {
return {
content: [{
type: 'text',
text: JSON.stringify({
success: false,
error: error instanceof Error ? error.message : 'Unknown error occurred'
}, null, 2)
}]
};
}
}
};
//# sourceMappingURL=text-to-speech.js.map