Elevenlabs

Produce voice audio and sound effects with ElevenLabsTools on a Gemini-powered agent and save the result as MP3.

Enable Agno agents to generate text-to-speech with ElevenLabs.

Prerequisites

  • Install dependencies: uv pip install agno elevenlabs google-genai.
  • Export your ElevenLabs API key: export ELEVEN_LABS_API_KEY=your_api_key.
  • Export your Google API key: export GOOGLE_API_KEY=your_api_key.
import base64
from textwrap import dedent

from agno.agent import Agent
from agno.models.google import Gemini
from agno.tools.eleven_labs import ElevenLabsTools
from agno.utils.media import save_base64_data

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

audio_agent = Agent(
    model=Gemini(id="gemini-2.5-pro"),
    tools=[
        ElevenLabsTools(
            voice_id="21m00Tcm4TlvDq8ikWAM",
            model_id="eleven_multilingual_v2",
        )
    ],
    description="You are an AI agent that can generate audio using the ElevenLabs API.",
    instructions=[
        dedent(
            """
            You have access to the ElevenLabs toolkit:
            - Use the `text_to_speech` tool to convert text or speech content into natural voice audio.
            - Use the `generate_sound_effect` tool to create sound effects from text descriptions.
            Keep the audio prompt as defined by the user.
            """
        ),
    ],
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    response = audio_agent.run(
        "Generate a very long audio of history of french revolution and tell me which subject it belongs to.",
    )

    if response.audio:
        print("Agent response:", response.content)
        base64_audio = base64.b64encode(response.audio[0].content).decode("utf-8")
        save_base64_data(base64_audio, "tmp/french_revolution.mp3")

    # response2 = audio_agent.run("Generate a glass breaking sound effect" , debug_mode=True)
    # if response2.audio:
    #     print("Agent response:", response2.content)
    #     base64_audio = base64.b64encode(response2.audio[0].content).decode("utf-8")
    #     save_base64_data(base64_audio, "tmp/glass_breaking_sound_effect.mp3")

Run the Example

# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno
git checkout d703c34f3abf3c41275d3fb2da6e0518a8881f24

# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate

uv pip install -U elevenlabs google-genai

python cookbook/91_tools/elevenlabs_tools.py

For details, see Elevenlabs cookbook.