Estimate the volume of an audio file.
The volume is the estimation of RMS values, sampled with a default window of 10ms.
Estimate the volume of an audio file.
The volume is the estimation of RMS values, sampled with a default window of 10ms.
Create an AudioVolume instance.
def __init__(self, audio, win_len=0.01):
"""Create an AudioVolume instance.
:param audio: (AudioPCM) The audio to work on.
:param win_len: (float) Window length to estimate the volume.
"""
super(AudioVolume, self).__init__(win_len)
pos = audio.tell()
audio.rewind()
nb_frames = int(win_len * audio.get_framerate())
nb_vols = int(audio.get_duration() / win_len) + 1
self._volumes = [0.0] * nb_vols
i = 0
while audio.tell() < audio.get_nframes():
frames = audio.read_frames(nb_frames)
a = AudioFrames(frames, audio.get_sampwidth(), audio.get_nchannels())
self._volumes[i] = a.rms()
i += 1
audio.seek(pos)
self._rms = audio.rms()