average-architect-28889
08/07/2025, 5:28 AMtall-airline-16756
08/07/2025, 5:28 AMtall-airline-16756
08/07/2025, 5:29 AMBackgroundAudioPlayer
class and configure it with a thinking_sound
parameter. Below is a sample implementation:
from livekit.agents import BackgroundAudioPlayer, AudioConfig
# Example using a custom audio file
custom_thinking_sound = AudioConfig(
source="/path/to/your-custom-audio.mp3", # Path to your audio file
volume=0.8, # Adjust the volume as needed
)
# Initialize BackgroundAudioPlayer with the custom thinking sound
background_audio = BackgroundAudioPlayer(
thinking_sound=custom_thinking_sound,
)
# Start the background audio player in your entrypoint function
from livekit.agents import AgentSession
async def entrypoint(ctx: JobContext):
session = AgentSession(
# Initialize your agent session with other configurations
)
await session.start(room=ctx.room)
# Initialize and start the background audio
background_audio = BackgroundAudioPlayer(
thinking_sound=custom_thinking_sound,
)
await background_audio.start(room=ctx.room, agent_session=session)
Key Points:
• The source
parameter can be a file path, BuiltinAudioClip
enum, or an AsyncIterator
yielding rtc.AudioFrame
objects.
• You can adjust the volume
parameter (0.0 to 1.0) to control the playback volume.
• Ensure the audio file is accessible and in a supported format.
If you want to randomize or provide multiple thinking sounds, you can pass a list of AudioConfig
objects to the thinking_sound
parameter.