dazzling-jordan-90714
02/17/2025, 2:55 AMparticipant_connected
is not working. what could be the possible issues ?
import logging
from livekit.agents import (
AutoSubscribe,
JobContext,
WorkerOptions,
cli,
llm,
)
from livekit.agents.pipeline import VoicePipelineAgent
from livekit.plugins import deepgram, silero
from livekit.rtc import RemoteParticipant
from .llm import LLM
logger = logging.getLogger("openai_assistant")
async def entrypoint(ctx: JobContext):
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
await ctx.wait_for_participant()
session_id = None
try:
session_id = f"session-{await ctx.room.sid}" if ctx.room else "default-session"
except Exception as e:
logger.warning(f"Failed to get room SID: {e}")
session_id = f"session-{ctx.room.name}" if ctx.room else "default-session"
transcript = []
assistant = VoicePipelineAgent(
vad=silero.VAD.load(activation_threshold=0.65),
stt=deepgram.STT(),
tts=deepgram.TTS(),
llm=LLM(session_id=session_id),
# whether the agent can be interrupted
allow_interruptions=True,
# sensitivity of when to interrupt
interrupt_speech_duration=0.6,
interrupt_min_words=0,
# minimal silence duration to consider end of turn
min_endpointing_delay=0.5,
)
def on_participant_connected(participant):
<http://logger.info|logger.info>(f"Participant connected: {participant.identity}")
ctx.room.on("participant_connected", on_participant_connected)
assistant.start(ctx.room)
@ctx.room.on("participant_disconnected")
def on_participant_disconnected(participant: RemoteParticipant):
<http://logger.info|logger.info>(f"Participant disconnected: {participant.identity}")
@assistant.on("user_speech_committed")
def on_user_speech_committed(msg: llm.ChatMessage):
<http://logger.info|logger.info>(f"Captured user message: {msg.content}")
transcript.append({"role": "user", "content": msg.content})
logger.debug(f"Transcript updated: {transcript}")
@assistant.on("agent_speech_interrupted")
def on_agent_speech_interrupted(msg: llm.ChatMessage):
<http://logger.info|logger.info>(f"Captured agent message: {msg.content}")
transcript.append({"role": "assistant", "content": msg.content})
logger.debug(f"Transcript updated: {transcript}")
@assistant.on("agent_speech_committed")
def on_agent_speech_committed(msg: llm.ChatMessage):
<http://logger.info|logger.info>(f"Captured agent message: {msg.content}")
transcript.append({"role": "assistant", "content": msg.content})
logger.debug(f"Transcript updated: {transcript}")
await assistant.say("Hello", allow_interruptions=False)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
gray-monkey-83525
02/17/2025, 2:55 AMparticipant_connected
event might not be working due to several reasons:
1. Event Registration Timing: Ensure that the event handler is registered before the room connection is established. According to LiveKit documentation, event listeners should be set up before connecting to the room to ensure they capture all events.
2. Correct Event Name: Double-check that the event name is correctly spelled as "participant_connected"
. Any typo will prevent the event from being triggered.
3. Room Connection: Verify that the room connection is successful. If the room is not connected, no events will be fired. You can check the connection state using the connection_state
property of the room object as described in the LiveKit documentation.
Would you like more detailed troubleshooting steps?
Sources:
- LiveKit documentation
- LiveKit documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.