SoundfileMixer
- class pipecat.audio.mixers.soundfile_mixer.SoundfileMixer(*, sound_files, default_sound, volume=0.4, mixing=True, loop=True, **kwargs)[source]
Bases:
BaseAudioMixer
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.
- Parameters:
sound_files (Mapping[str, str])
default_sound (str)
volume (float)
mixing (bool)
loop (bool)
- async start(sample_rate)[source]
This will be called from the output transport when the transport is started. It can be used to initialize the mixer. The output transport sample rate is provided so the mixer can adjust to that sample rate.
- Parameters:
sample_rate (int)
- async stop()[source]
This will be called from the output transport when the transport is stopping.
- async process_frame(frame)[source]
This will be called when the output transport receives a MixerControlFrame.
- Parameters:
frame (MixerControlFrame)
- async mix(audio)[source]
This is called with the audio that is about to be sent from the output transport and that should be mixed with the mixer audio if the mixer is enabled.
- Parameters:
audio (bytes)
- Return type:
bytes