soundfile_mixer

Soundfile-based audio mixer for file playback integration.

Provides an audio mixer that combines incoming audio with audio loaded from files using the soundfile library. Supports multiple audio formats and runtime configuration changes.

class pipecat.audio.mixers.soundfile_mixer.SoundfileMixer(*, sound_files: Mapping[str, str], default_sound: str, volume: float = 0.4, mixing: bool = True, loop: bool = True, **kwargs)[source]

Bases: BaseAudioMixer

Audio mixer that combines incoming audio with file-based audio.

This is an audio mixer that mixes incoming audio with audio from a file. It uses the soundfile library to load files so it supports multiple formats. The audio files need to only have one channel (mono) and it needs to match the sample rate of the output transport.

Multiple files can be loaded, each with a different name. The MixerUpdateSettingsFrame has the following settings available: sound (str) and volume (float) to be able to update to a different sound file or to change the volume at runtime.

__init__(*, sound_files: Mapping[str, str], default_sound: str, volume: float = 0.4, mixing: bool = True, loop: bool = True, **kwargs)[source]

Initialize the soundfile mixer.

Parameters:
  • sound_files – Mapping of sound names to file paths for loading.

  • default_sound – Name of the default sound to play initially.

  • volume – Mixing volume level (0.0 to 1.0). Defaults to 0.4.

  • mixing – Whether mixing is initially enabled. Defaults to True.

  • loop – Whether to loop audio files when they end. Defaults to True.

  • **kwargs – Additional arguments passed to parent class.

async start(sample_rate: int)[source]

Initialize the mixer and load all sound files.

Parameters:

sample_rate – The sample rate of the output transport in Hz.

async stop()[source]

Clean up mixer resources.

Currently performs no cleanup as sound data is managed by garbage collection.

async process_frame(frame: MixerControlFrame)[source]

Process mixer control frames to update settings or enable/disable mixing.

Parameters:

frame – The mixer control frame to process.

async mix(audio: bytes) bytes[source]

Mix transport audio with the current sound file.

Parameters:

audio – Raw audio bytes from the transport to mix.

Returns:

Mixed audio bytes combining transport and file audio.