Translation Agent
Transcribe, translate, and regenerate audio with GroqTools.
Translate a short audio clip into English and generate WAV speech. The current adaptation selects an explicit Orpheus model and checks its 200-character input limit before making the speech request.
Run a current adaptation
Install agno groq openai, set GROQ_API_KEY and OPENAI_API_KEY, and put a short real recording at tmp/sample-fr.mp3. Save this as translation_agent.py:
from pathlib import Path
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.models.groq import GroqTools
audio_path = Path("tmp/sample-fr.mp3")
if not audio_path.is_file():
raise FileNotFoundError(f"Provide a short recording at {audio_path}")
groq_tools = GroqTools(
tts_model="canopylabs/orpheus-v1-english",
tts_voice="troy",
enable_generate_speech=False,
)
verified_translation: dict[str, str] = {}
def translate_recording() -> str:
"""Translate the configured local recording into English."""
verified_translation.clear()
translated = groq_tools.translate_audio(str(audio_path.resolve()))
if translated.startswith("Failed to translate audio source "):
raise RuntimeError(translated)
if not translated.strip():
raise RuntimeError("The translation was empty")
verified_translation["text"] = translated.strip()
return translated
agent = Agent(
model=OpenAIChat(id="gpt-5.2"),
tools=[translate_recording],
instructions="Use the audio translation tool. Return only the English translation.",
)
agent.run("Use translate_recording to translate the configured recording into English.")
# Use the successful tool result, never arbitrary final model prose or an apology.
text = verified_translation.get("text")
if text is None:
raise RuntimeError("No successful audio translation was recorded")
if len(text) > 200:
raise ValueError("Use a shorter clip or split the translation into chunks of at most 200 characters")
# Speech is called explicitly after checking the provider's input limit.
result = groq_tools.generate_speech(agent=agent, text_input=text)
if not result.audios or result.audios[0].content is None:
raise RuntimeError(f"Speech generation failed: {result.content}")
output_path = Path("tmp/sample-en.wav")
output_path.parent.mkdir(parents=True, exist_ok=True)
output_path.write_bytes(result.audios[0].content)
print(output_path)Run python translation_agent.py. The OpenAI model calls the checked translation tool. Speech uses the recorded successful tool result; missing calls and translation failures stop before TTS. Groq translates the recording and generates speech. Review the translation before using it in another application.
Historical source
The original cookbook below is retained for comparison. It also remains unchanged in the reviewed main source and cannot run as written: it assumes a missing input file, uses the retired PlayAI default, requests music, and labels WAV bytes as MP3. Use the complete adaptation above.
Original code
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
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: ignoreEnvironment setup
Use these dependencies and credentials with the current adaptation above. The historical source is not a runnable release example.
Install dependencies
uv pip install -U agno groq openaiSet API keys
export GROQ_API_KEY="your_groq_api_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"