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):
self.stop_threads.set()
if self.camera_thread and self.camera_thread.is_alive():
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.frame_consumer_thread.join()
self.client.leave()
@@ -223,7 +225,11 @@ class DailyTransportService(EventHandler):
all_audio_frames = bytearray()
while True:
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:
self.logger.info("Stopping frame consumer thread")
return

View File

@@ -26,32 +26,52 @@ async def main(room_url, token):
tts = AzureTTSService()
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",
"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:
transport.run()
inference_text = await inference_text_process
tts_iterator = tts.run_tts(inference_text)
(image, audio) = await asyncio.gather(
*[dalle.run_image_gen(inference_text, "1024x1024"), anext(tts_iterator)]
)
transport.output_queue.put(OutputQueueFrame(FrameType.IMAGE_FRAME, image[1]))
transport.output_queue.put(OutputQueueFrame(FrameType.AUDIO_FRAME, audio))
async for audio in tts_iterator:
transport.output_queue.put(
OutputQueueFrame(FrameType.AUDIO_FRAME, audio)
)
await asyncio.sleep(meeting_duration_minutes * 60)
months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
]
await asyncio.gather(*[show_month(month) for month in months])
finally:
transport.stop()
print("Done")