Want to play a music while executing a tool it should play parallelly with the execution of the api clal

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 ?

@darryncampbell adding to check if this is possible

Yes, you can play music from a file in an agent.

Use BackgroundAudioPlayer and pass a local file path. Local files are supported and decoded automatically, as described in the Background audio guide.

Thanks for your insights @darryncampbell
But i wanted to know specifically if using session.say() we are able to play a music or not

as mentioned in this doc we can play audio using session.say(). Does that mean this audio should be a voice only or it can be a music as well ?

In that case, the audio can be anything, it doesn’t have to be text, as documented here: Agent speech and audio | LiveKit Documentation

Playing audio through session.say is really designed for use cases where you always want the agent to say the same thing every time (such as reading some legalese) as it saves TTS credits if you play it through a wave file, rather than generate the same thing every time. I don’t see why it wouldn’t work for your approach, but that is why I recommended the BackgroundAudioPlayer.