From fc19a55f04c87dd8cf1e9ad296ef06776e4a4215 Mon Sep 17 00:00:00 2001 From: Moishe Lettvin Date: Tue, 27 Feb 2024 13:51:55 -0500 Subject: [PATCH] ... --- src/dailyai/services/ai_services.py | 2 +- src/dailyai/services/base_transport_service.py | 1 - src/dailyai/services/daily_transport_service.py | 4 ++-- src/examples/foundational/01-say-one-thing.py | 8 ++++---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/dailyai/services/ai_services.py b/src/dailyai/services/ai_services.py index 04a81f962..b71e4e4e8 100644 --- a/src/dailyai/services/ai_services.py +++ b/src/dailyai/services/ai_services.py @@ -187,7 +187,7 @@ class TTSService(AIService): # Convenience function to send the audio for a sentence to the given queue async def say(self, sentence, queue: asyncio.Queue|None=None): - queue = queue or self.output_queue + queue = queue or self.sink if not queue: raise Exception("No queue to send audio to") await self.run_to_queue(queue, [TextQueueFrame(sentence)]) diff --git a/src/dailyai/services/base_transport_service.py b/src/dailyai/services/base_transport_service.py index 1e1547b68..6bd3a83bf 100644 --- a/src/dailyai/services/base_transport_service.py +++ b/src/dailyai/services/base_transport_service.py @@ -82,7 +82,6 @@ class BaseTransportService(): self._stop_threads.set() - #await self.send_queue.put(EndStreamQueueFrame()) await async_output_queue_marshal_task await self.send_queue.join() self._frame_consumer_thread.join() diff --git a/src/dailyai/services/daily_transport_service.py b/src/dailyai/services/daily_transport_service.py index 44c2f63fb..32e14dc7e 100644 --- a/src/dailyai/services/daily_transport_service.py +++ b/src/dailyai/services/daily_transport_service.py @@ -205,7 +205,7 @@ class DailyTransportService(BaseTransportService, EventHandler): def _post_run(self): self.client.leave() - def on_first_other_participant_joined(self): + def on_first_other_participant_joined(self, participant): pass def call_joined(self, join_data, client_error): @@ -226,7 +226,7 @@ class DailyTransportService(BaseTransportService, EventHandler): def on_participant_joined(self, participant): if not self._other_participant_has_joined and participant["id"] != self._my_participant_id: self._other_participant_has_joined = True - self.on_first_other_participant_joined() + self.on_first_other_participant_joined(participant) def on_participant_left(self, participant, reason): if len(self.client.participants()) < self._min_others_count + 1: diff --git a/src/examples/foundational/01-say-one-thing.py b/src/examples/foundational/01-say-one-thing.py index cb063dfd2..27af1284a 100644 --- a/src/examples/foundational/01-say-one-thing.py +++ b/src/examples/foundational/01-say-one-thing.py @@ -1,6 +1,7 @@ import asyncio import aiohttp import os +from dailyai.queue_frame import EndStreamQueueFrame from dailyai.services.daily_transport_service import DailyTransportService from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService @@ -42,15 +43,14 @@ async def main(room_url): ) # Register an event handler so we can play the audio when the participant joins. - @transport.event_handler("on_participant_joined") - async def on_participant_joined(transport, participant): + @transport.event_handler("on_first_other_participant_joined") + async def on_first_other_participant_joined(transport, participant): nonlocal tts - if participant["info"]["isLocal"]: - return await tts.say( "Hello there, " + participant["info"]["userName"] + "!" ) + await tts.sink.put(EndStreamQueueFrame()) # wait for the output queue to be empty, then leave the meeting await transport.stop_when_done()