Merge pull request #53 from daily-co/fix_other_joined_event
Don't do time-consuming processing in `on_other_joined_event`
This commit is contained in:
@@ -32,7 +32,7 @@ class FalImageGenService(ImageGenService):
|
|||||||
async def run_image_gen(self, sentence) -> tuple[str, bytes]:
|
async def run_image_gen(self, sentence) -> tuple[str, bytes]:
|
||||||
def get_image_url(sentence, size):
|
def get_image_url(sentence, size):
|
||||||
handler = fal.apps.submit(
|
handler = fal.apps.submit(
|
||||||
# "110602490-fast-sdxl",
|
#"110602490-fast-sdxl",
|
||||||
"fal-ai/fast-sdxl",
|
"fal-ai/fast-sdxl",
|
||||||
arguments={"prompt": sentence},
|
arguments={"prompt": sentence},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -28,21 +28,31 @@ async def main(room_url):
|
|||||||
voice_id=os.getenv("ELEVENLABS_VOICE_ID"),
|
voice_id=os.getenv("ELEVENLABS_VOICE_ID"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
other_joined_event = asyncio.Event()
|
||||||
|
participant_name = ''
|
||||||
|
|
||||||
|
async def say_hello():
|
||||||
|
nonlocal tts
|
||||||
|
nonlocal participant_name
|
||||||
|
|
||||||
|
await other_joined_event.wait()
|
||||||
|
await tts.say(
|
||||||
|
"Hello there, " + participant_name + "!",
|
||||||
|
transport.send_queue,
|
||||||
|
)
|
||||||
|
await transport.stop_when_done()
|
||||||
|
|
||||||
# Register an event handler so we can play the audio when the participant joins.
|
# Register an event handler so we can play the audio when the participant joins.
|
||||||
@transport.event_handler("on_participant_joined")
|
@transport.event_handler("on_participant_joined")
|
||||||
async def on_participant_joined(transport, participant):
|
async def on_participant_joined(transport, participant):
|
||||||
if participant["info"]["isLocal"]:
|
if participant["info"]["isLocal"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
await tts.say(
|
nonlocal participant_name
|
||||||
"Hello there, " + participant["info"]["userName"] + "!",
|
participant_name = participant["info"]["userName"] or ''
|
||||||
transport.send_queue,
|
other_joined_event.set()
|
||||||
)
|
|
||||||
|
|
||||||
# wait for the output queue to be empty, then leave the meeting
|
await asyncio.gather(transport.run(), say_hello())
|
||||||
await transport.stop_when_done()
|
|
||||||
|
|
||||||
await transport.run()
|
|
||||||
del tts
|
del tts
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,15 +42,20 @@ async def main(room_url):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@transport.event_handler("on_first_other_participant_joined")
|
other_joined_event = asyncio.Event()
|
||||||
async def on_first_other_participant_joined(transport):
|
async def speak_from_llm():
|
||||||
|
await other_joined_event.wait()
|
||||||
await tts.run_to_queue(
|
await tts.run_to_queue(
|
||||||
transport.send_queue,
|
transport.send_queue,
|
||||||
llm.run([LLMMessagesQueueFrame(messages)]),
|
llm.run([LLMMessagesQueueFrame(messages)])
|
||||||
)
|
)
|
||||||
await transport.stop_when_done()
|
await transport.stop_when_done()
|
||||||
|
|
||||||
await transport.run()
|
@transport.event_handler("on_first_other_participant_joined")
|
||||||
|
async def on_first_other_participant_joined(transport):
|
||||||
|
other_joined_event.set()
|
||||||
|
|
||||||
|
await asyncio.gather(transport.run(), speak_from_llm())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ async def main(room_url):
|
|||||||
camera_enabled=True,
|
camera_enabled=True,
|
||||||
camera_width=1024,
|
camera_width=1024,
|
||||||
camera_height=1024,
|
camera_height=1024,
|
||||||
|
duration_minutes=1
|
||||||
)
|
)
|
||||||
|
|
||||||
imagegen = FalImageGenService(
|
imagegen = FalImageGenService(
|
||||||
@@ -32,13 +33,19 @@ async def main(room_url):
|
|||||||
key_secret=os.getenv("FAL_KEY_SECRET"),
|
key_secret=os.getenv("FAL_KEY_SECRET"),
|
||||||
)
|
)
|
||||||
|
|
||||||
@transport.event_handler("on_first_other_participant_joined")
|
other_joined_event = asyncio.Event()
|
||||||
async def on_first_other_participant_joined(transport):
|
|
||||||
|
async def show_image():
|
||||||
|
await other_joined_event.wait()
|
||||||
await imagegen.run_to_queue(
|
await imagegen.run_to_queue(
|
||||||
transport.send_queue, [TextFrame("a cat in the style of picasso")]
|
transport.send_queue, [TextFrame("a cat in the style of picasso")]
|
||||||
)
|
)
|
||||||
|
|
||||||
await transport.run()
|
@transport.event_handler("on_first_other_participant_joined")
|
||||||
|
async def on_first_other_participant_joined(transport):
|
||||||
|
other_joined_event.set()
|
||||||
|
|
||||||
|
await asyncio.gather(transport.run(), show_image())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -62,8 +62,15 @@ async def main(room_url: str):
|
|||||||
await source_queue.put(EndFrame())
|
await source_queue.put(EndFrame())
|
||||||
pipeline_run_task = pipeline.run_pipeline()
|
pipeline_run_task = pipeline.run_pipeline()
|
||||||
|
|
||||||
|
other_participant_joined = asyncio.Event()
|
||||||
|
|
||||||
@transport.event_handler("on_first_other_participant_joined")
|
@transport.event_handler("on_first_other_participant_joined")
|
||||||
async def on_first_other_participant_joined(transport):
|
async def on_first_other_participant_joined(transport):
|
||||||
|
other_participant_joined.set()
|
||||||
|
|
||||||
|
async def say_something():
|
||||||
|
await other_participant_joined.wait()
|
||||||
|
|
||||||
await azure_tts.say(
|
await azure_tts.say(
|
||||||
"My friend the LLM is now going to tell a joke about llamas.",
|
"My friend the LLM is now going to tell a joke about llamas.",
|
||||||
transport.send_queue,
|
transport.send_queue,
|
||||||
@@ -87,9 +94,8 @@ async def main(room_url: str):
|
|||||||
break
|
break
|
||||||
|
|
||||||
await asyncio.gather(pipeline_run_task, buffer_to_send_queue())
|
await asyncio.gather(pipeline_run_task, buffer_to_send_queue())
|
||||||
await transport.stop_when_done()
|
|
||||||
|
|
||||||
await transport.run()
|
await asyncio.gather(transport.run(), say_something())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -140,12 +140,18 @@ async def main(room_url):
|
|||||||
)
|
)
|
||||||
pipeline_task = pipeline.run_pipeline()
|
pipeline_task = pipeline.run_pipeline()
|
||||||
|
|
||||||
|
other_joined = asyncio.Event()
|
||||||
|
|
||||||
@transport.event_handler("on_first_other_participant_joined")
|
@transport.event_handler("on_first_other_participant_joined")
|
||||||
async def on_first_other_participant_joined(transport):
|
async def on_first_other_participant_joined(transport):
|
||||||
|
other_joined.set()
|
||||||
|
|
||||||
|
async def show_calendar():
|
||||||
|
await other_joined.wait()
|
||||||
await pipeline_task
|
await pipeline_task
|
||||||
await transport.stop_when_done()
|
await transport.stop_when_done()
|
||||||
|
|
||||||
await transport.run()
|
await asyncio.gather(transport.run(), show_calendar())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ async def main(room_url: str, token):
|
|||||||
async def on_first_other_participant_joined(transport):
|
async def on_first_other_participant_joined(transport):
|
||||||
await tts.say("Hi, I'm listening!", transport.send_queue)
|
await tts.say("Hi, I'm listening!", transport.send_queue)
|
||||||
|
|
||||||
async def handle_transcriptions():
|
async def have_conversation():
|
||||||
messages = [
|
messages = [
|
||||||
{
|
{
|
||||||
"role": "system",
|
"role": "system",
|
||||||
@@ -75,7 +75,7 @@ async def main(room_url: str, token):
|
|||||||
|
|
||||||
transport.transcription_settings["extra"]["endpointing"] = True
|
transport.transcription_settings["extra"]["endpointing"] = True
|
||||||
transport.transcription_settings["extra"]["punctuate"] = True
|
transport.transcription_settings["extra"]["punctuate"] = True
|
||||||
await asyncio.gather(transport.run(), handle_transcriptions())
|
await asyncio.gather(transport.run(), have_conversation())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user