import argparse import asyncio import re from dailyai.services.daily_transport_service import DailyTransportService from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService from dailyai.queue_frame import QueueFrame, FrameType async def main(room_url:str): global transport global llm global tts transport = DailyTransportService( room_url, None, "Say Two Things Bot", 1, ) transport.mic_enabled = True transport.mic_sample_rate = 16000 transport.camera_enabled = False llm = AzureLLMService() tts = AzureTTSService() @transport.event_handler("on_participant_joined") async def on_joined(transport, participant): if participant["id"] == transport.my_participant_id: return # queue two pieces of speech: one specified as a text literal, # and one generated by an llm. We'll kick off the llm first, and let # it generate a response while we're speaking the literal string. # # Note that in this case, we don't use `run_llm_async` because we're # taking advantage of the time spent speaking the first phrase to generate # the entire LLM response, and this happens asynchronously in a task. llm_response_task = asyncio.create_task(llm.run_llm( [{"role": "system", "content": "tell the user a joke about llamas"}] )) async for audio_chunk in tts.run_tts("My friend the LLM is now going to tell a joke about llamas."): transport.output_queue.put(QueueFrame(FrameType.AUDIO_FRAME, audio_chunk)) llm_response = await llm_response_task async for audio_chunk in tts.run_tts(llm_response): transport.output_queue.put(QueueFrame(FrameType.AUDIO_FRAME, audio_chunk)) # wait for the output queue to be empty, then leave the meeting transport.output_queue.join() transport.stop() await transport.run() if __name__ == "__main__": parser = argparse.ArgumentParser(description="Simple Daily Bot Sample") parser.add_argument( "-u", "--url", type=str, required=True, help="URL of the Daily room to join" ) args: argparse.Namespace = parser.parse_args() asyncio.run(main(args.url))