steep-balloon-41261
12/02/2025, 4:48 PMtall-airline-16756
12/02/2025, 4:49 PMtall-airline-16756
12/02/2025, 4:49 PMtall-airline-16756
12/02/2025, 4:50 PMuv add "livekit-agents[gladia]~=1.2" python-dotenv
1. .env:
LIVEKIT_API_KEY=...
LIVEKIT_API_SECRET=...
LIVEKIT_URL=wss://your-room.livekit.cloud
GLADIA_API_KEY=...
Minimal translator agent (Python)
from dotenv import load_dotenv
from livekit import agents
from livekit.agents import AgentSession, Agent
from livekit.plugins import gladia, cartesia
from livekit.plugins.turn_detector import MultilingualModel
load_dotenv()
class TranslatorAgent(Agent):
def __init__(self):
super().__init__(instructions="You are a real-time translator. Reply only with translated text.")
# Gladia STT with realtime translation enabled (input auto-detected -> translate to French)
stt = gladia.STT(
translation_enabled=True,
languages=None, # None = auto-detect input language
translation_target_languages=["fr"] # output language(s)
)
# Cartesia TTS for the translated audio
tts = cartesia.TTS(model="sonic-multilingual")
@agents.rtc_session()
async def session_entrypoint(ctx: agents.JobContext):
session = AgentSession(
stt=stt,
tts=tts,
llm=None, # optional: add LLM for rewriting
vad=None, # optional VAD plugin
turn_detection=MultilingualModel()
)
await session.start(room=ctx.room, agent=TranslatorAgent())
if __name__ == "__main__":
agents.cli.run_app()
Notes
• Gladia returns incremental partial transcripts and translated text; the session can start TTS on partials so playback begins before final STT completes.
• If the final transcript changes the response, preemptive TTS is canceled and replaced automatically.
• To add an LLM step (e.g., refine translation), set llm= to your LLM plugin; the pipeline will feed translated text into the LLM before TTS.
• To support multiple target languages, set translation_target_languages to a list (e.g., ["fr","de"]) and handle routing in your session logic.
Would you like a version that includes an LLM rewrite step or a JS/Node example?
Sources: Gladia STT plugin guide | LiveKit Docs | Text and transcriptions | LiveKit docs