add on_first_other_participant_joined event

This commit is contained in:
Moishe Lettvin
2024-01-12 08:39:56 -05:00
parent 37207745c9
commit ec1f2362c5
3 changed files with 11 additions and 12 deletions

View File

@@ -29,7 +29,7 @@ class AIService:
while True:
frame = await self.input_queue.get()
print(f"{self.__class__.__name__} got frame:", frame.frame_type)
self.logger.debug(f"{self.__class__.__name__} got frame:", frame.frame_type)
if frame.frame_type == FrameType.END_STREAM:
self.input_queue.task_done()
await self.output_queue.put(QueueFrame(FrameType.END_STREAM, None))
@@ -80,7 +80,6 @@ class LLMService(AIService):
messages: list[dict[str, str]] = frame.frame_data
async for message in self.run_llm_async_sentences(messages):
print("got message", message)
await self.output_queue.put(QueueFrame(FrameType.SENTENCE_FRAME, message))
@@ -100,7 +99,6 @@ class TTSService(AIService):
if not self.output_queue:
raise Exception("Output queue must be set before using the run method.")
print(frame.frame_type)
if frame.frame_type == FrameType.SENTENCE_FRAME:
if type(frame.frame_data) != str:
raise Exception("TTS service requires a string for the data field")

View File

@@ -45,6 +45,8 @@ class DailyTransportService(EventHandler):
self.camera_height = 768
self.camera_enabled = False
self.other_participant_has_joined = False
self.camera_thread = None
self.frame_consumer_thread = None
@@ -231,6 +233,9 @@ class DailyTransportService(EventHandler):
def stop(self):
self.stop_threads.set()
def on_first_other_participant_joined(self):
pass
def call_joined(self, join_data, client_error):
self.logger.info(f"Call_joined: {join_data}, {client_error}")
@@ -241,7 +246,9 @@ class DailyTransportService(EventHandler):
pass
def on_participant_joined(self, participant):
pass
if not self.other_participant_has_joined and participant["id"] != self.my_participant_id:
self.other_participant_has_joined = True
self.on_first_other_participant_joined()
def on_participant_left(self, participant, reason):
if len(self.client.participants()) < 2:

View File

@@ -34,14 +34,8 @@ async def main(room_url):
llm_task = asyncio.create_task(llm.run())
has_joined = False
@transport.event_handler("on_participant_joined")
async def on_participant_joined(transport, participant):
nonlocal has_joined
if participant["id"] == transport.my_participant_id or has_joined:
return
has_joined = True
@transport.event_handler("on_first_other_participant_joined")
async def on_first_other_participant_joined(transport):
await asyncio.gather(llm_task, tts.run())
# wait for the output queue to be empty, then leave the meeting