Skip to content

Commit

Permalink
Merge pull request #53 from daily-co/fix_other_joined_event
Browse files Browse the repository at this point in the history
Don't do time-consuming processing in `on_other_joined_event`
  • Loading branch information
Moishe authored Mar 11, 2024
2 parents de026cc + f8ae264 commit c75a3fb
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/dailyai/services/fal_ai_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
async def run_image_gen(self, sentence) -> tuple[str, bytes]:
def get_image_url(sentence, size):
handler = fal.apps.submit(
# "110602490-fast-sdxl",
#"110602490-fast-sdxl",
"fal-ai/fast-sdxl",
arguments={"prompt": sentence},
)
Expand Down
26 changes: 18 additions & 8 deletions src/examples/foundational/01-say-one-thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,31 @@ async def main(room_url):
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.
@transport.event_handler("on_participant_joined")
async def on_participant_joined(transport, participant):
if participant["info"]["isLocal"]:
return

await tts.say(
"Hello there, " + participant["info"]["userName"] + "!",
transport.send_queue,
)

# wait for the output queue to be empty, then leave the meeting
await transport.stop_when_done()
nonlocal participant_name
participant_name = participant["info"]["userName"] or ''
other_joined_event.set()

await transport.run()
await asyncio.gather(transport.run(), say_hello())
del tts


Expand Down
13 changes: 9 additions & 4 deletions src/examples/foundational/02-llm-say-one-thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@ async def main(room_url):
}
]

@transport.event_handler("on_first_other_participant_joined")
async def on_first_other_participant_joined(transport):
other_joined_event = asyncio.Event()
async def speak_from_llm():
await other_joined_event.wait()
await tts.run_to_queue(
transport.send_queue,
llm.run([LLMMessagesQueueFrame(messages)]),
llm.run([LLMMessagesQueueFrame(messages)])
)
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__":
Expand Down
13 changes: 10 additions & 3 deletions src/examples/foundational/03-still-frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async def main(room_url):
camera_enabled=True,
camera_width=1024,
camera_height=1024,
duration_minutes=1
)

imagegen = FalImageGenService(
Expand All @@ -32,13 +33,19 @@ async def main(room_url):
key_secret=os.getenv("FAL_KEY_SECRET"),
)

@transport.event_handler("on_first_other_participant_joined")
async def on_first_other_participant_joined(transport):
other_joined_event = asyncio.Event()

async def show_image():
await other_joined_event.wait()
await imagegen.run_to_queue(
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__":
Expand Down
10 changes: 8 additions & 2 deletions src/examples/foundational/04-utterance-and-speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ async def main(room_url: str):
await source_queue.put(EndFrame())
pipeline_run_task = pipeline.run_pipeline()

other_participant_joined = asyncio.Event()

@transport.event_handler("on_first_other_participant_joined")
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(
"My friend the LLM is now going to tell a joke about llamas.",
transport.send_queue,
Expand All @@ -87,9 +94,8 @@ async def buffer_to_send_queue():
break

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__":
Expand Down
8 changes: 7 additions & 1 deletion src/examples/foundational/05-sync-speech-and-image.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,18 @@ async def main(room_url):
)
pipeline_task = pipeline.run_pipeline()

other_joined = asyncio.Event()

@transport.event_handler("on_first_other_participant_joined")
async def on_first_other_participant_joined(transport):
other_joined.set()

async def show_calendar():
await other_joined.wait()
await pipeline_task
await transport.stop_when_done()

await transport.run()
await asyncio.gather(transport.run(), show_calendar())


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions src/examples/foundational/06-listen-and-respond.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def main(room_url: str, token):
async def on_first_other_participant_joined(transport):
await tts.say("Hi, I'm listening!", transport.send_queue)

async def handle_transcriptions():
async def have_conversation():
messages = [
{
"role": "system",
Expand All @@ -75,7 +75,7 @@ async def handle_transcriptions():

transport.transcription_settings["extra"]["endpointing"] = True
transport.transcription_settings["extra"]["punctuate"] = True
await asyncio.gather(transport.run(), handle_transcriptions())
await asyncio.gather(transport.run(), have_conversation())


if __name__ == "__main__":
Expand Down

0 comments on commit c75a3fb

Please sign in to comment.