text_to_speech
Convert text to speech and save as MP3 files using customizable voice options for audio content creation.
Instructions
Convert the given text into speech and save as MP3 file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| voice_id | No | JBFqnCBsd6RMkjVDRZzb |
Implementation Reference
- server.py:31-57 (handler)The core handler function for the 'text_to_speech' tool, registered via @mcp.tool(). It converts input text to speech using the ElevenLabs API, saves the audio as a unique MP3 file, and returns the filename or error message.@mcp.tool() def text_to_speech(text: str, voice_id: str = "JBFqnCBsd6RMkjVDRZzb") -> str: """Convert the given text into speech and save as MP3 file""" import uuid try: # Generate unique filename audio_filename = f"speech_{uuid.uuid4().hex[:8]}.mp3" # Generate audio using ElevenLabs audio = client_elevenlabs.text_to_speech.convert( text=text, voice_id=voice_id, model_id="eleven_multilingual_v2" ) # Save audio to file with open(audio_filename, "wb") as f: for chunk in audio: if chunk: f.write(chunk) return f"Audio generated successfully! Saved as: {audio_filename}" except Exception as e: return f"Error generating speech: {str(e)}"