Groq Translation Agent

Translate French audio and generate English speech with GroqTools.

translation_agent.py
"""
Groq Translation Agent
======================

Cookbook example for `groq/translation_agent.py`.
"""

import base64
from pathlib import Path

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.models.groq import GroqTools
from agno.utils.media import save_base64_data

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

path = "tmp/sample-fr.mp3"

agent = Agent(
    name="Groq Translation Agent",
    model=OpenAIChat(id="gpt-5.2"),
    tools=[GroqTools()],
    cache_session=True,
)

response = agent.run(
    f"Let's transcribe the audio file located at '{path}' and translate it to English. After that generate a new music audio file using the translated text."
)

if response and response.audio:
    base64_audio = base64.b64encode(response.audio[0].content).decode("utf-8")
    save_base64_data(base64_audio, Path("tmp/sample-en.mp3"))  # type: ignore

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

Current Example

The preserved source uses PlayAI speech defaults that Groq retired on 31 December 2025. Use the supported English Orpheus model and voice, supply an actual French MP3, and save the returned WAV bytes with a .wav extension. This example produces speech.

translation_current.py
from pathlib import Path

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.models.groq import GroqTools

input_path = Path("tmp/sample-fr.mp3")
if not input_path.is_file():
    raise FileNotFoundError(f"Place a French MP3 at {input_path} before running.")

agent = Agent(
    name="Groq Translation Agent",
    model=OpenAIChat(id="gpt-5.2"),
    tools=[
        GroqTools(
            tts_model="canopylabs/orpheus-v1-english",
            tts_voice="hannah",
        )
    ],
)
response = agent.run(
    f"Translate the French audio file at '{input_path}' to English, "
    "then use generate_speech to produce spoken English from the translated text."
)

if not response.audio or not response.audio[0].content:
    raise RuntimeError("The agent returned no speech audio. Inspect the run for tool errors.")

output_path = Path("tmp/sample-en.wav")
output_path.write_bytes(response.audio[0].content)
print(f"Saved English speech to {output_path}")

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno groq openai

Export your API keys

export GROQ_API_KEY="your_groq_api_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"

Supply the French audio

Create a tmp directory beside translation_current.py and place your French recording there as sample-fr.mp3. Run the script from that directory's parent so tmp/sample-fr.mp3 resolves correctly.

Run the example

Save the Current Example as translation_current.py, then run:

python translation_current.py

Full source: cookbook/90_models/groq/translation_agent.py