volume
Audio volume tracking over a rolling window of recent audio.
- class pipecat.audio.volume.AudioVolumeTracker[source]
Bases:
objectTracks the volume of an audio stream over a rolling window.
Audio is fed in chunks of any size with
update(), which retains the most recentVOLUME_WINDOW_SECSof it, andvolumemeasures that window. Volume reads 0 until the window holds enough audio for loudness to be measurable, and the window is discarded if the sample rate changes.Measuring costs a few hundred microseconds and grows with the sample rate, so it happens on read and the result is cached until more audio arrives. Callers that report volume less often than they receive audio pay only for the reads.
Audio is expected to be mono; interleaved channels would be measured as if they were consecutive samples.
- property volume: float
Get the volume of the audio in the rolling window.
- Returns:
Volume between 0 (quiet) and 1 (loud). Reads 0 until the window holds a measurable amount of audio.