stop_when_done
This commit is contained in:
@@ -163,8 +163,7 @@ class TTSService(AIService):
|
|||||||
|
|
||||||
# Convenience function to send the audio for a sentence to the given queue
|
# Convenience function to send the audio for a sentence to the given queue
|
||||||
async def say(self, sentence, queue: asyncio.Queue):
|
async def say(self, sentence, queue: asyncio.Queue):
|
||||||
async for audio_chunk in self.run_tts(sentence):
|
await self.run_to_queue(queue, [QueueFrame(FrameType.SENTENCE, sentence)])
|
||||||
await queue.put(QueueFrame(FrameType.AUDIO, audio_chunk))
|
|
||||||
|
|
||||||
|
|
||||||
class ImageGenService(AIService):
|
class ImageGenService(AIService):
|
||||||
|
|||||||
@@ -209,6 +209,10 @@ class DailyTransportService(EventHandler):
|
|||||||
def wait_for_send_queue_to_empty(self):
|
def wait_for_send_queue_to_empty(self):
|
||||||
self.threadsafe_send_queue.join()
|
self.threadsafe_send_queue.join()
|
||||||
|
|
||||||
|
def stop_when_done(self):
|
||||||
|
self.wait_for_send_queue_to_empty()
|
||||||
|
self.stop()
|
||||||
|
|
||||||
async def run(self) -> None:
|
async def run(self) -> None:
|
||||||
self.configure_daily()
|
self.configure_daily()
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from typing import AsyncGenerator
|
|||||||
from dailyai.queue_frame import QueueFrame, FrameType
|
from dailyai.queue_frame import QueueFrame, FrameType
|
||||||
from dailyai.services.daily_transport_service import DailyTransportService
|
from dailyai.services.daily_transport_service import DailyTransportService
|
||||||
from dailyai.services.azure_ai_services import AzureTTSService
|
from dailyai.services.azure_ai_services import AzureTTSService
|
||||||
|
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
||||||
|
|
||||||
async def main(room_url):
|
async def main(room_url):
|
||||||
# create a transport service object using environment variables for
|
# create a transport service object using environment variables for
|
||||||
@@ -23,9 +24,7 @@ async def main(room_url):
|
|||||||
meeting_duration_minutes,
|
meeting_duration_minutes,
|
||||||
)
|
)
|
||||||
transport.mic_enabled = True
|
transport.mic_enabled = True
|
||||||
|
tts = ElevenLabsTTSService(voice_id="ErXwobaYiN019PkySvjV")
|
||||||
# similarly, create a tts service
|
|
||||||
tts = AzureTTSService()
|
|
||||||
|
|
||||||
# Register an event handler so we can play the audio when the participant joins.
|
# Register an event handler so we can play the audio when the participant joins.
|
||||||
@transport.event_handler("on_participant_joined")
|
@transport.event_handler("on_participant_joined")
|
||||||
@@ -33,11 +32,13 @@ async def main(room_url):
|
|||||||
if participant["info"]["isLocal"]:
|
if participant["info"]["isLocal"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
await tts.say("Hello there, " + participant["info"]["userName"] + "!", transport.send_queue)
|
await tts.say(
|
||||||
|
"Hello there, " + participant["info"]["userName"] + "!",
|
||||||
|
transport.send_queue,
|
||||||
|
)
|
||||||
|
|
||||||
# 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.wait_for_send_queue_to_empty()
|
transport.stop_when_done()
|
||||||
transport.stop()
|
|
||||||
|
|
||||||
await transport.run()
|
await transport.run()
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ async def main(room_url):
|
|||||||
async def on_first_other_participant_joined(transport):
|
async def on_first_other_participant_joined(transport):
|
||||||
await tts_task
|
await tts_task
|
||||||
|
|
||||||
transport.wait_for_send_queue_to_empty()
|
transport.stop_when_done()
|
||||||
transport.stop()
|
|
||||||
|
|
||||||
await transport.run()
|
await transport.run()
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +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.wait_for_send_queue_to_empty()
|
transport.stop_when_done()
|
||||||
transport.stop()
|
|
||||||
|
|
||||||
await transport.run()
|
await transport.run()
|
||||||
|
|
||||||
|
|||||||
@@ -115,8 +115,7 @@ async def main(room_url):
|
|||||||
await transport.send_queue.put(QueueFrame(FrameType.AUDIO, audio))
|
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.wait_for_send_queue_to_empty()
|
transport.stop_when_done()
|
||||||
transport.stop()
|
|
||||||
|
|
||||||
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