A little cleanup
This commit is contained in:
@@ -44,7 +44,7 @@ class TTSService(AIService):
|
|||||||
class ImageGenService(AIService):
|
class ImageGenService(AIService):
|
||||||
# Renders the image. Returns an Image object.
|
# Renders the image. Returns an Image object.
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
async def run_image_gen(self, sentence) -> tuple[str, bytes]:
|
async def run_image_gen(self, sentence, size) -> tuple[str, bytes]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -153,20 +153,20 @@ class AzureImageGenService(ImageGenService):
|
|||||||
api_version=api_version,
|
api_version=api_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def run_image_gen(self, sentence) -> tuple[str, Image.Image]:
|
async def run_image_gen(self, sentence, size) -> tuple[str, bytes]:
|
||||||
self.logger.info("Generating azure image", sentence)
|
self.logger.info("Generating azure image", sentence)
|
||||||
|
|
||||||
image = self.client.images.generate(
|
image = self.client.images.generate(
|
||||||
model=self.model,
|
model=self.model,
|
||||||
prompt=sentence,
|
prompt=sentence,
|
||||||
n=1,
|
n=1,
|
||||||
size=f"1024x1024",
|
size=size,
|
||||||
)
|
)
|
||||||
|
|
||||||
url = image["data"][0]["url"]
|
url = image["data"][0]["url"]
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
|
|
||||||
dalle_stream = io.BytesIO(response.content)
|
dalle_stream = io.BytesIO(response.content)
|
||||||
dalle_im = Image.open(dalle_stream)
|
dalle_im = Image.open(dalle_stream.tobytes())
|
||||||
|
|
||||||
return (url, dalle_im)
|
return (url, dalle_im)
|
||||||
|
|||||||
@@ -194,11 +194,7 @@ class DailyTransportService(EventHandler):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def on_transcription_message(self, message):
|
def on_transcription_message(self, message):
|
||||||
with self.tracer.start_as_current_span(
|
pass
|
||||||
"on_transcription_message", context=self.ctx
|
|
||||||
):
|
|
||||||
if message["session_id"] != self.my_participant_id:
|
|
||||||
self.handle_transcription_fragment(message["text"])
|
|
||||||
|
|
||||||
def on_transcription_stopped(self, stopped_by, stopped_by_error):
|
def on_transcription_stopped(self, stopped_by, stopped_by_error):
|
||||||
self.logger.info(f"Transcription stopped {stopped_by}, {stopped_by_error}")
|
self.logger.info(f"Transcription stopped {stopped_by}, {stopped_by_error}")
|
||||||
@@ -216,10 +212,9 @@ class DailyTransportService(EventHandler):
|
|||||||
try:
|
try:
|
||||||
while not self.stop_threads.is_set():
|
while not self.stop_threads.is_set():
|
||||||
if self.image:
|
if self.image:
|
||||||
print("rendering image")
|
|
||||||
self.camera.write_frame(self.image)
|
self.camera.write_frame(self.image)
|
||||||
|
|
||||||
time.sleep(1.0 / 24) # 24 fps
|
time.sleep(1.0 / 8) # 8 fps
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Exception {e} in camera thread.")
|
self.logger.error(f"Exception {e} in camera thread.")
|
||||||
print("exiting run_camera thread")
|
print("exiting run_camera thread")
|
||||||
@@ -231,9 +226,13 @@ class DailyTransportService(EventHandler):
|
|||||||
all_audio_frames = bytearray()
|
all_audio_frames = bytearray()
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
frames: OutputQueueFrame | list[OutputQueueFrame] = self.output_queue.get()
|
frames_or_frame: OutputQueueFrame | list[OutputQueueFrame] = self.output_queue.get()
|
||||||
if type(frames) != list:
|
if type(frames_or_frame) == OutputQueueFrame:
|
||||||
frames = [frames]
|
frames: list[OutputQueueFrame] = [frames_or_frame]
|
||||||
|
elif type(frames_or_frame) == list:
|
||||||
|
frames: list[OutputQueueFrame] = frames_or_frame
|
||||||
|
else:
|
||||||
|
raise Exception("Unknown type in output queue")
|
||||||
|
|
||||||
for frame in frames:
|
for frame in frames:
|
||||||
if frame.frame_type == FrameType.END_STREAM:
|
if frame.frame_type == FrameType.END_STREAM:
|
||||||
|
|||||||
@@ -8,12 +8,13 @@ async def main(room_url, token):
|
|||||||
class Sample05Transport(DailyTransportService):
|
class Sample05Transport(DailyTransportService):
|
||||||
def on_participant_joined(self, participant):
|
def on_participant_joined(self, participant):
|
||||||
super().on_participant_joined(participant)
|
super().on_participant_joined(participant)
|
||||||
|
asyncio.run(show_all_months())
|
||||||
|
|
||||||
meeting_duration_minutes = 4
|
meeting_duration_minutes = 4
|
||||||
transport = Sample05Transport(
|
transport = Sample05Transport(
|
||||||
room_url,
|
room_url,
|
||||||
token,
|
token,
|
||||||
"Simple Bot",
|
"Month Narration Bot",
|
||||||
meeting_duration_minutes,
|
meeting_duration_minutes,
|
||||||
)
|
)
|
||||||
transport.mic_enabled = True
|
transport.mic_enabled = True
|
||||||
@@ -56,11 +57,12 @@ async def main(room_url, token):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
async def show_all_months():
|
||||||
transport.run()
|
# for now just two to avoid 429s with Azure
|
||||||
months = [
|
months = [
|
||||||
"January",
|
"January",
|
||||||
"February",
|
"February",]
|
||||||
|
"""
|
||||||
"March",
|
"March",
|
||||||
"April",
|
"April",
|
||||||
"May",
|
"May",
|
||||||
@@ -70,14 +72,16 @@ async def main(room_url, token):
|
|||||||
"September",
|
"September",
|
||||||
"October",
|
"October",
|
||||||
"November",
|
"November",
|
||||||
"December"
|
"December",
|
||||||
]
|
]
|
||||||
sleeper = asyncio.sleep(meeting_duration_minutes * 60)
|
"""
|
||||||
print("gathering")
|
print("gathering")
|
||||||
await asyncio.gather(*[show_month(month) for month in months])
|
await asyncio.gather(*[show_month(month) for month in months])
|
||||||
print("waiting")
|
|
||||||
await sleeper
|
|
||||||
print("done")
|
print("done")
|
||||||
|
|
||||||
|
try:
|
||||||
|
transport.run()
|
||||||
|
await asyncio.sleep(meeting_duration_minutes * 60)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Exception", e)
|
print("Exception", e)
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user