Clean up example 5
This commit is contained in:
@@ -206,11 +206,12 @@ class DailyTransportService(EventHandler):
|
|||||||
if type(frame) == QueueFrame and frame.frame_type == FrameType.END_STREAM:
|
if type(frame) == QueueFrame and frame.frame_type == FrameType.END_STREAM:
|
||||||
break
|
break
|
||||||
|
|
||||||
def wait_for_send_queue_to_empty(self):
|
async def wait_for_send_queue_to_empty(self):
|
||||||
|
await self.send_queue.join()
|
||||||
self.threadsafe_send_queue.join()
|
self.threadsafe_send_queue.join()
|
||||||
|
|
||||||
def stop_when_done(self):
|
async def stop_when_done(self):
|
||||||
self.wait_for_send_queue_to_empty()
|
await self.wait_for_send_queue_to_empty()
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ async def main(room_url):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# wait for the output queue to be empty, then leave the meeting
|
# wait for the output queue to be empty, then leave the meeting
|
||||||
transport.stop_when_done()
|
await transport.stop_when_done()
|
||||||
|
|
||||||
await transport.run()
|
await transport.run()
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ async def main(room_url):
|
|||||||
@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):
|
||||||
await tts_task
|
await tts_task
|
||||||
|
await transport.stop_when_done()
|
||||||
transport.stop_when_done()
|
|
||||||
|
|
||||||
await transport.run()
|
await transport.run()
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ async def main(room_url:str):
|
|||||||
|
|
||||||
await asyncio.gather(llm_response_task, buffer_to_send_queue())
|
await asyncio.gather(llm_response_task, buffer_to_send_queue())
|
||||||
|
|
||||||
transport.stop_when_done()
|
await transport.stop_when_done()
|
||||||
|
|
||||||
await transport.run()
|
await transport.run()
|
||||||
|
|
||||||
|
|||||||
@@ -41,9 +41,6 @@ async def main(room_url):
|
|||||||
return all_audio
|
return all_audio
|
||||||
|
|
||||||
async def get_month_data(month):
|
async def get_month_data(month):
|
||||||
image_text = ""
|
|
||||||
tts_tasks = []
|
|
||||||
first_sentence = True
|
|
||||||
messages = [
|
messages = [
|
||||||
{
|
{
|
||||||
"role": "system",
|
"role": "system",
|
||||||
@@ -51,41 +48,23 @@ async def main(room_url):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
async for frame in SentenceAggregator().run(llm.run([QueueFrame(FrameType.LLM_MESSAGE, messages)])):
|
image_description = await llm.run_llm(messages)
|
||||||
if type(frame.frame_data) != str:
|
to_speak = f"{month}: {image_description}"
|
||||||
raise Exception("LLM service requires a string for the data field")
|
(audio, image_data) = await asyncio.gather(
|
||||||
|
get_all_audio(to_speak), dalle.run_image_gen(image_description)
|
||||||
sentence: str = frame.frame_data
|
|
||||||
image_text += sentence
|
|
||||||
|
|
||||||
if first_sentence:
|
|
||||||
sentence = f"{month}: {sentence}"
|
|
||||||
else:
|
|
||||||
first_sentence = False
|
|
||||||
|
|
||||||
tts_tasks.append(get_all_audio(sentence))
|
|
||||||
|
|
||||||
tts_tasks.insert(0, dalle.run_image_gen(image_text))
|
|
||||||
|
|
||||||
print(f"waiting for tasks to finish for {month}")
|
|
||||||
data = await asyncio.gather(
|
|
||||||
*tts_tasks
|
|
||||||
)
|
)
|
||||||
|
|
||||||
print(f"done gathering tts tasks for {month}")
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"month": month,
|
"month": month,
|
||||||
"text": image_text,
|
"text": image_description,
|
||||||
"image": data[0][1],
|
"image": image_data[1],
|
||||||
"audio": data[1:],
|
"audio": audio,
|
||||||
}
|
}
|
||||||
|
|
||||||
months: list[str] = [
|
months: list[str] = [
|
||||||
"January",
|
"January",
|
||||||
"February",
|
"February",
|
||||||
"March"]
|
"March",
|
||||||
"""
|
|
||||||
"April",
|
"April",
|
||||||
"May",
|
"May",
|
||||||
"June",
|
"June",
|
||||||
@@ -96,7 +75,6 @@ async def main(room_url):
|
|||||||
"November",
|
"November",
|
||||||
"December",
|
"December",
|
||||||
]
|
]
|
||||||
"""
|
|
||||||
|
|
||||||
@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):
|
||||||
@@ -108,14 +86,12 @@ async def main(room_url):
|
|||||||
await transport.send_queue.put(
|
await transport.send_queue.put(
|
||||||
[
|
[
|
||||||
QueueFrame(FrameType.IMAGE, data["image"]),
|
QueueFrame(FrameType.IMAGE, data["image"]),
|
||||||
QueueFrame(FrameType.AUDIO, data["audio"][0]),
|
QueueFrame(FrameType.AUDIO, data["audio"]),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
for audio in data["audio"][1:]:
|
|
||||||
await transport.send_queue.put(QueueFrame(FrameType.AUDIO, audio))
|
|
||||||
|
|
||||||
# wait for the output queue to be empty, then leave the meeting
|
# wait for the output queue to be empty, then leave the meeting
|
||||||
transport.stop_when_done()
|
await transport.stop_when_done()
|
||||||
|
|
||||||
month_tasks = [asyncio.create_task(get_month_data(month)) for month in months]
|
month_tasks = [asyncio.create_task(get_month_data(month)) for month in months]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user