Manages background audio playback for LiveKit agent sessions

This class handles playing ambient sounds and manages audio track publishing. It supports:

  • Continuous ambient sound playback with looping
  • Thinking sound playback during agent processing
  • Multiple simultaneous audio streams via AudioMixer
  • Volume control and probability-based sound selection
  • Integration with LiveKit rooms and agent sessions

Example

const player = new BackgroundAudioPlayer({
ambientSound: { source: BuiltinAudioClip.OFFICE_AMBIENCE, volume: 0.8 },
thinkingSound: { source: BuiltinAudioClip.KEYBOARD_TYPING, volume: 0.6 },
});

await player.start({ room, agentSession });

Constructors

Methods

  • Get the current track publication

    Returns undefined | LocalTrackPublication

  • Start the background audio system, publishing the audio track and beginning playback of any configured ambient sound.

    If ambientSound is provided (and contains file paths), they will loop automatically. If ambientSound contains AsyncIterators, they are assumed to be already infinite or looped.

    Parameters

    Returns Promise<void>