more demo cleanup, allow bundled frames in output_queue

This commit is contained in:
Moishe Lettvin
2024-01-04 17:54:13 -05:00
parent fcd9a248d9
commit cd2c9700ad
2 changed files with 80 additions and 54 deletions

View File

@@ -147,7 +147,9 @@ class DailyTransportService(EventHandler):
def stop(self): def stop(self):
self.stop_threads.set() self.stop_threads.set()
if self.camera_thread and self.camera_thread.is_alive():
self.camera_thread.join() self.camera_thread.join()
if self.frame_consumer_thread and self.frame_consumer_thread.is_alive():
self.output_queue.put(OutputQueueFrame(FrameType.END_STREAM, None)) self.output_queue.put(OutputQueueFrame(FrameType.END_STREAM, None))
self.frame_consumer_thread.join() self.frame_consumer_thread.join()
self.client.leave() self.client.leave()
@@ -223,7 +225,11 @@ class DailyTransportService(EventHandler):
all_audio_frames = bytearray() all_audio_frames = bytearray()
while True: while True:
try: try:
frame: OutputQueueFrame = self.output_queue.get() frames: OutputQueueFrame | list[OutputQueueFrame] = self.output_queue.get()
if type(frames) != list:
frames = [frames]
for frame in frames:
if frame.frame_type == FrameType.END_STREAM: if frame.frame_type == FrameType.END_STREAM:
self.logger.info("Stopping frame consumer thread") self.logger.info("Stopping frame consumer thread")
return return

View File

@@ -26,32 +26,52 @@ async def main(room_url, token):
tts = AzureTTSService() tts = AzureTTSService()
dalle = AzureImageGenServiceREST() dalle = AzureImageGenServiceREST()
inference_text_process = llm.run_llm( async def get_all_audio(text):
all_audio = bytearray()
async for audio in tts.run_tts(text):
all_audio.append(audio)
return all_audio
async def show_month(month):
print(f"Running llm for {month}")
inference_text = await llm.run_llm(
[ [
{ {
"role": "system", "role": "system",
"content": f"Describe a nature photograph suitable for use in a calendar, for the month of January. Include only the image description with no preamble." "content": f"Describe a nature photograph suitable for use in a calendar, for the month of {month}. Include only the image description with no preamble."
} }
] ]
) )
print(f"got llm for {month}")
(image, audio) = await asyncio.gather(
*[dalle.run_image_gen(inference_text, "1024x1024"), get_all_audio(inference_text)]
)
print(f"Got audio and video for {month}")
transport.output_queue.put(
[
OutputQueueFrame(FrameType.IMAGE_FRAME, image[1]),
OutputQueueFrame(FrameType.AUDIO_FRAME, audio),
]
)
try: try:
transport.run() transport.run()
months = [
inference_text = await inference_text_process "January",
"February",
tts_iterator = tts.run_tts(inference_text) "March",
(image, audio) = await asyncio.gather( "April",
*[dalle.run_image_gen(inference_text, "1024x1024"), anext(tts_iterator)] "May",
) "June",
transport.output_queue.put(OutputQueueFrame(FrameType.IMAGE_FRAME, image[1])) "July",
transport.output_queue.put(OutputQueueFrame(FrameType.AUDIO_FRAME, audio)) "August",
async for audio in tts_iterator: "September",
transport.output_queue.put( "October",
OutputQueueFrame(FrameType.AUDIO_FRAME, audio) "November",
) ]
await asyncio.gather(*[show_month(month) for month in months])
await asyncio.sleep(meeting_duration_minutes * 60)
finally: finally:
transport.stop() transport.stop()
print("Done") print("Done")