better-truck-92255
09/07/2025, 2:39 PMbetter-truck-92255
09/07/2025, 2:40 PMimport os
from pathlib import Path
from dotenv import load_dotenv
from livekit.agents import (
JobContext,
WorkerOptions,
cli,
)
from livekit.agents.voice import Agent, AgentSession
from livekit.plugins import elevenlabs, openai, speechmatics
load_dotenv(dotenv_path=Path(__file__).parent.parent / ".env")
class Anna(Agent):
def __init__(self) -> None:
super().__init__(
instructions="""
You are a helpful agent.
You speak Norwegian.
You are here to take any messages from the user.
Do not make up any information.
Do not ask any questions, just take messages,
Do not say much.
""",
stt=speechmatics.STT(
api_key=os.getenv("SPEECHMATICS_API_KEY",""), language="no"
),
# Tried multiple values for this, but none worked
turn_detection="vad",
# Tried multiple values for this, but none worked
allow_interruptions=False,
use_tts_aligned_transcript=True,
llm=openai.LLM(model="gpt-4o"),
tts=elevenlabs.TTS(
voice_id=os.getenv("ELEVENLABS_VOICE_ID",""),
language="no",
model="eleven_turbo_v2_5",
api_key=os.getenv("ELEVENLABS_API_KEY",""),
),
)
async def entrypoint(ctx: JobContext):
await ctx.connect()
session: AgentSession = AgentSession(
# Tried multiple values for this, but none worked
allow_interruptions=False,
# Tried multiple values for this, but none worked
min_interruption_duration=1
)
# Cleaner realtime captions to clients (don't wait to sync back to audio)
agent = Anna()
await session.start(agent=agent, room=ctx.room)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))better-truck-92255
09/07/2025, 9:00 PMagreeable-plumber-27227
09/11/2025, 1:22 PMbetter-truck-92255
09/12/2025, 12:53 PMagreeable-plumber-27227
09/12/2025, 5:32 PMbetter-truck-92255
09/12/2025, 5:33 PMdelightful-match-91444
09/22/2025, 6:49 AM