From 20a9c6a938250fdc233facb5efc97502134493d0 Mon Sep 17 00:00:00 2001 From: Moishe Lettvin Date: Tue, 9 Jan 2024 06:12:24 -0500 Subject: [PATCH] simplify the join, no need for END_STREAM --- .../theoretical-to-real/01-say-one-thing.py | 5 +-- .../02-llm-say-one-thing.py | 5 +-- .../04-utterance-and-speech.py | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 src/samples/theoretical-to-real/04-utterance-and-speech.py diff --git a/src/samples/theoretical-to-real/01-say-one-thing.py b/src/samples/theoretical-to-real/01-say-one-thing.py index 50b7e01f3..fd9ce43f4 100644 --- a/src/samples/theoretical-to-real/01-say-one-thing.py +++ b/src/samples/theoretical-to-real/01-say-one-thing.py @@ -39,11 +39,8 @@ async def main(room_url): async for audio in audio_generator: transport.output_queue.put(OutputQueueFrame(FrameType.AUDIO_FRAME, audio)) - # Put an "end stream" item on the queue, which will cause it to shut down when it's processed - # all the audio. - transport.output_queue.put(OutputQueueFrame(FrameType.END_STREAM, None)) + # wait for the output queue to be empty, then leave the meeting transport.output_queue.join() - transport.stop() await transport.run() diff --git a/src/samples/theoretical-to-real/02-llm-say-one-thing.py b/src/samples/theoretical-to-real/02-llm-say-one-thing.py index 02ede4457..7b717d4ea 100644 --- a/src/samples/theoretical-to-real/02-llm-say-one-thing.py +++ b/src/samples/theoretical-to-real/02-llm-say-one-thing.py @@ -43,11 +43,8 @@ async def main(room_url): transport.output_queue.put(OutputQueueFrame(FrameType.AUDIO_FRAME, audio)) current_text = "" - # Put an "end stream" item on the queue, which will cause it to shut down when it's processed - # all the audio. - transport.output_queue.put(OutputQueueFrame(FrameType.END_STREAM, None)) + # wait for the output queue to be empty, then leave the meeting transport.output_queue.join() - transport.stop() await transport.run() diff --git a/src/samples/theoretical-to-real/04-utterance-and-speech.py b/src/samples/theoretical-to-real/04-utterance-and-speech.py new file mode 100644 index 000000000..1ec5dccfb --- /dev/null +++ b/src/samples/theoretical-to-real/04-utterance-and-speech.py @@ -0,0 +1,43 @@ +import argparse +import asyncio + +from dailyai.output_queue import OutputQueueFrame, FrameType +from dailyai.services.daily_transport_service import DailyTransportService +from dailyai.services.open_ai_services import OpenAIImageGenService + +local_joined = False +participant_joined = False + +async def main(room_url): + meeting_duration_minutes = 1 + transport = DailyTransportService( + room_url, + None, + "Show a still frame image", + meeting_duration_minutes, + ) + transport.mic_enabled = False + transport.camera_enabled = True + transport.camera_width = 1024 + transport.camera_height = 1024 + + imagegen = OpenAIImageGenService() + image_task = asyncio.create_task(imagegen.run_image_gen("a cat in the style of picasso", "1024x1024")) + + @transport.event_handler("on_participant_joined") + async def on_participant_joined(transport, participant): + (_, image_bytes) = await image_task + transport.output_queue.put(OutputQueueFrame(FrameType.IMAGE_FRAME, image_bytes)) + + await transport.run() + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Simple Daily Bot Sample") + parser.add_argument( + "-u", "--url", type=str, required=True, help="URL of the Daily room to join" + ) + + args: argparse.Namespace = parser.parse_args() + + asyncio.run(main(args.url))