fix: filter own key events, fix RoomOptions None, wait for participant
- Skip bot own encryption_keys events in on_unknown handler - Always pass valid RoomOptions to AgentSession.start() - Wait up to 10s for remote participant to connect before starting pipeline Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
5
bot.py
5
bot.py
@@ -370,9 +370,12 @@ class Bot:
|
|||||||
await self._route_verification(room, event)
|
await self._route_verification(room, event)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Forward encryption key events to active voice sessions
|
# Forward encryption key events to active voice sessions (skip our own)
|
||||||
if event.type == ENCRYPTION_KEYS_TYPE:
|
if event.type == ENCRYPTION_KEYS_TYPE:
|
||||||
|
if event.sender == BOT_USER:
|
||||||
|
return # ignore our own key events
|
||||||
room_id = room.room_id
|
room_id = room.room_id
|
||||||
|
logger.info("Got encryption_keys timeline event from %s in %s", event.sender, room_id)
|
||||||
vs = self.voice_sessions.get(room_id)
|
vs = self.voice_sessions.get(room_id)
|
||||||
if vs:
|
if vs:
|
||||||
content = event.source.get("content", {})
|
content = event.source.get("content", {})
|
||||||
|
|||||||
20
voice.py
20
voice.py
@@ -214,12 +214,22 @@ class VoiceSession:
|
|||||||
logger.info("Connected (E2EE=HKDF), remote=%d",
|
logger.info("Connected (E2EE=HKDF), remote=%d",
|
||||||
len(self.lk_room.remote_participants))
|
len(self.lk_room.remote_participants))
|
||||||
|
|
||||||
# Find the remote participant to link to
|
# Find the remote participant, wait up to 10s if not yet connected
|
||||||
remote_identity = None
|
remote_identity = None
|
||||||
for p in self.lk_room.remote_participants.values():
|
for p in self.lk_room.remote_participants.values():
|
||||||
remote_identity = p.identity
|
remote_identity = p.identity
|
||||||
logger.info("Linking to remote participant: %s", remote_identity)
|
|
||||||
break
|
break
|
||||||
|
if not remote_identity:
|
||||||
|
logger.info("No remote participant yet, waiting...")
|
||||||
|
for _ in range(100):
|
||||||
|
await asyncio.sleep(0.1)
|
||||||
|
for p in self.lk_room.remote_participants.values():
|
||||||
|
remote_identity = p.identity
|
||||||
|
break
|
||||||
|
if remote_identity:
|
||||||
|
break
|
||||||
|
if remote_identity:
|
||||||
|
logger.info("Linking to remote participant: %s", remote_identity)
|
||||||
|
|
||||||
# Voice pipeline — German male voice (Daniel)
|
# Voice pipeline — German male voice (Daniel)
|
||||||
self._http_session = aiohttp.ClientSession()
|
self._http_session = aiohttp.ClientSession()
|
||||||
@@ -242,13 +252,13 @@ class VoiceSession:
|
|||||||
logger.info("AGENT_SPEECH: %s", msg.text_content)
|
logger.info("AGENT_SPEECH: %s", msg.text_content)
|
||||||
|
|
||||||
agent = Agent(instructions=VOICE_PROMPT)
|
agent = Agent(instructions=VOICE_PROMPT)
|
||||||
room_opts = room_io.RoomOptions(
|
io_opts = room_io.RoomOptions(
|
||||||
participant_identity=remote_identity,
|
participant_identity=remote_identity,
|
||||||
) if remote_identity else None
|
) if remote_identity else room_io.RoomOptions()
|
||||||
await self.session.start(
|
await self.session.start(
|
||||||
agent=agent,
|
agent=agent,
|
||||||
room=self.lk_room,
|
room=self.lk_room,
|
||||||
room_options=room_opts,
|
room_options=io_opts,
|
||||||
)
|
)
|
||||||
logger.info("Voice pipeline started (voice=%s, linked_to=%s)", voice_id, remote_identity)
|
logger.info("Voice pipeline started (voice=%s, linked_to=%s)", voice_id, remote_identity)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user