auditok.util.AudioEnergyValidator

class auditok.util.AudioEnergyValidator(energy_threshold, sample_width, channels, use_channel=None)[source]

A validator based on audio signal energy. For an input window of N audio samples (see AudioEnergyValidator.is_valid()), the energy is computed as:

\[energy = 20 \log(\sqrt({1}/{N}\sum_{i}^{N}{a_i}^2)) % # noqa: W605\]

where a_i is the i-th audio sample.

Parameters:
  • energy_threshold (float) – minimum energy that audio window should have to be valid.
  • sample_width (int) – size in bytes of one audio sample.
  • channels (int) – number of channels of audio data.
  • use_channel ({None, "any", "mix", "avg", "average"} or int) –

    channel to use for energy computation. The following values are accepted:

    • None (alias “any”) : compute energy for each of the channels and return the maximum value.
    • ”mix” (alias “avg” or “average”) : compute the average channel then compute its energy.
    • int (>= 0 , < channels) : compute the energy of the specified channel and ignore the other ones.
Returns:

energy – energy of the audio window.

Return type:

float

__init__(energy_threshold, sample_width, channels, use_channel=None)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(energy_threshold, sample_width, …) Initialize self.
is_valid(data)
param data:array of raw audio data