hallowed-book-84502
08/04/2025, 9:10 AMBVCTelephony for best results
noise_cancellation=noise_cancellation.BVC(),
),
)
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
if name == "__main__":
agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))tall-airline-16756
08/04/2025, 9:11 AMtall-airline-16756
08/04/2025, 9:11 AMconnect() method is called before accessing the local_participant property.
Here’s how you can fix it:
1. Call room.connect() with the required URL and token before accessing the local participant.
2. Ensure the connection is established before interacting with the local_participant.
For example:
room = rtc.Room()
# Connect to the room
await room.connect("<ws://localhost:7880>", "your_token")
# Access the local participant after connecting
local_participant = room.local_participant
Make sure your code follows this sequence to avoid the error.
Sources: livekit-rtc/livekit/rtc/room.pyhallowed-book-84502
08/04/2025, 9:12 AMtall-airline-16756
08/04/2025, 9:12 AMentrypoint function by adding the connect() method. Here’s the updated snippet for you:
async def entrypoint(ctx: agents.JobContext):
session = AgentSession(
stt=openai.STT(model="gpt-4o-transcribe"),
llm=openai.LLM(model="gpt-4o-mini"),
tts=openai.TTS(model="gpt-4o-mini-tts", voice="ash", instructions="Speak in a friendly and conversational tone."),
vad=silero.VAD.load(),
)
# Connect to the room before starting the session
await ctx.room.connect("<ws://your-server-url>", "your_token")
await session.start(
room=ctx.room,
agent=Assistant(),
room_input_options=RoomInputOptions(
noise_cancellation=noise_cancellation.BVC(),
),
)
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
Just a quick heads-up: don’t forget to swap out "<ws://your-server-url>" and "your_token" with your actual WebSocket URL and token from your LiveKit server.
This little change will make sure your room is connected before the session kicks off, so you won’t run into that pesky error. Hope this helps!hallowed-book-84502
08/04/2025, 9:13 AMtall-airline-16756
08/04/2025, 9:13 AMLIVEKIT_API_KEY and LIVEKIT_API_SECRET are set up in your environment variables.
2. Then, you can use this function to create your token:
from livekit import api
from dotenv import load_dotenv
import os
# Load environment variables
load_dotenv()
def generate_token(room_name, identity=None, name=None):
"""
Generate a LiveKit access token for room access.
Args:
room_name (str): The name of the room to join
identity (str, optional): The participant identity. Defaults to None.
name (str, optional): The display name. Defaults to None.
Returns:
str: JWT token string
"""
if not identity:
identity = f"python-user-{room_name}"
if not name:
name = identity
# Just a quick check to make sure your environment variables are set
if not (LIVEKIT_API_KEY := os.getenv("LIVEKIT_API_KEY")) or not (LIVEKIT_API_SECRET := os.getenv("LIVEKIT_API_SECRET")):
raise ValueError("LIVEKIT_API_KEY and LIVEKIT_API_SECRET must be set in .env file")
# Now, let’s create the token with video permissions
token = (
api.AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET)
.with_identity(identity)
.with_name(name)
.with_grants(
api.VideoGrants(
room_join=True,
room=room_name,
)
)
.to_jwt()
)
return token
Here’s how you might use it:
# Generate a token for a participant
token = generate_token("my-room", identity="user123", name="Participant Name")
# Then, use this token to connect to your LiveKit room
Don’t forget to have your .env file set up like this:
LIVEKIT_API_KEY=your_api_key
LIVEKIT_API_SECRET=your_api_secret
This will give you a JWT token ready to connect to your LiveKit room. If you hit any bumps or have questions, just give me a shout—I’m here to help!
Sources: Generating tokens | LiveKit Docs | stream_audio.py | complex-agents/drive-thru/frontend/app/api/connection-details/route.tshallowed-book-84502
08/04/2025, 9:17 AMtall-airline-16756
08/04/2025, 9:17 AM--dev flag by running this command:
livekit-server --dev
This will launch LiveKit using the default API key and secret: devkey and secret. Super simple!
If you want to connect to the server from other devices on your network, no worries! Just add the --bind flag like this:
livekit-server --dev --bind 0.0.0.0
If you hit any snags or want a hand with anything else, just give me a shout—I’m here to help!
Sources: cmd/server/main.go | Running LiveKit locally | LiveKit Docs