Skip to main content
Glama

text_to_voice

Generate three voice previews from text using ElevenLabs technology. Saves audio files to a specified directory for voice design and testing purposes.

Instructions

Create voice previews from a text prompt. Creates three previews with slight variations. Saves the previews to a given directory. If no text is provided, the tool will auto-generate text.

Voice preview files are saved as: voice_design_(generated_voice_id)_(timestamp).mp3 Example file name: voice_design_Ya2J5uIa5Pq14DNPsbC1_20250403_164949.mp3 ⚠️ COST WARNING: This tool makes an API call to ElevenLabs which may incur costs. Only use when explicitly requested by the user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
output_directoryNo
textNo
voice_descriptionYes

Implementation Reference

  • The handler function that implements the 'text_to_voice' tool. It generates three voice previews from a description using the ElevenLabs API, saves the MP3 audio files, and returns the file paths and generated voice IDs.
    def text_to_voice( voice_description: str, text: str | None = None, output_directory: str | None = None, ) -> TextContent: if voice_description == "": make_error("Voice description is required.") previews = client.text_to_voice.create_previews( voice_description=voice_description, text=text, auto_generate_text=True if text is None else False, ) output_path = make_output_path(output_directory, base_path) generated_voice_ids = [] output_file_paths = [] for preview in previews.previews: output_file_name = make_output_file( "voice_design", preview.generated_voice_id, output_path, "mp3", full_id=True ) output_file_paths.append(str(output_file_name)) generated_voice_ids.append(preview.generated_voice_id) audio_bytes = base64.b64decode(preview.audio_base_64) with open(output_path / output_file_name, "wb") as f: f.write(audio_bytes) return TextContent( type="text", text=f"Success. Files saved at: {', '.join(output_file_paths)}. Generated voice IDs are: {', '.join(generated_voice_ids)}", )
  • Registers the 'text_to_voice' tool with the MCP server using the @mcp.tool decorator, providing a detailed description that serves as the tool schema.
    @mcp.tool( description="""Create voice previews from a text prompt. Creates three previews with slight variations. Saves the previews to a given directory. If no text is provided, the tool will auto-generate text. Voice preview files are saved as: voice_design_(generated_voice_id)_(timestamp).mp3 Example file name: voice_design_Ya2J5uIa5Pq14DNPsbC1_20250403_164949.mp3 ⚠️ COST WARNING: This tool makes an API call to ElevenLabs which may incur costs. Only use when explicitly requested by the user. """ )
  • Supporting tool 'create_voice_from_preview' that uses the generated voice ID from 'text_to_voice' to add the voice to the library.
    @mcp.tool( description="""Add a generated voice to the voice library. Uses the voice ID from the `text_to_voice` tool. ⚠️ COST WARNING: This tool makes an API call to ElevenLabs which may incur costs. Only use when explicitly requested by the user. """ ) def create_voice_from_preview( generated_voice_id: str, voice_name: str, voice_description: str, ) -> TextContent: voice = client.text_to_voice.create_voice_from_preview( voice_name=voice_name, voice_description=voice_description, generated_voice_id=generated_voice_id, ) return TextContent( type="text", text=f"Success. Voice created: {voice.name} with ID:{voice.voice_id}", )

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/projectservan8n/elevenlabs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server