from livekit import rtc
from livekit.agents import Agent, RunContext, function_tool
# Pre-synthesize a hold message once at startup
HOLD_FRAMES: list[rtc.AudioFrame] = []
async def preload_hold_message(tts) -> None:
global HOLD_FRAMES
async for event in tts.synthesize("Let me check that for you."):
HOLD_FRAMES.append(event.frame)
class MyAgent(Agent):
@function_tool()
async def check_order_status(
self,
context: RunContext,
order_id: str,
) -> str:
"""Check the status of an order.
Args:
order_id: The order ID to look up.
"""
async def cached_audio():
for frame in HOLD_FRAMES:
yield frame
# Play the hold message concurrently — don't await
hold_handle = context.session.say(
"Let me check that for you.",
audio=cached_audio(),
add_to_chat_ctx=False,
)
# Call the external API (runs while the hold message plays)
result = await fetch_order_status(order_id)
# If the API returned before the hold message finished, cancel it
if not hold_handle.interrupted and not hold_handle.done():
hold_handle.interrupt()
return result
i found this code in this doc https://docs.livekit.io/agents/multimodality/audio/#caching-tts
Can anyone confirm is it possible to play a music from a file here ?