• Re: How to check whether audio bytes contain empty noise or actual voic

    From Stefan Ram@21:1/5 to marc nicole on Fri Oct 25 16:43:11 2024
    marc nicole <mk1853387@gmail.com> wrote or quoted:
    I hope this question is not very far from the main topic of this list, but
    I have a hard time finding a way to check whether audio data samples are >containing empty noise or actual significant voice/noise.

    The Spectral Flatness Measure (SFM), also called Wiener entropy, can
    separate the wheat from the chaff when it comes to how noise-like
    a signal is. This measure runs the gamut from 0 to 1, where:
    1 means you've hit pay dirt with perfect white noise (flat spectrum),
    0 is as pure as a Napa Valley Chardonnay (single frequency).
    (Everything in between is just different shades of gnarly.)

    import numpy as np
    from scipy.signal import welch

    def noiseness(signal, fs):
    # Compute the power spectral density
    f, psd = welch(signal, fs, nperseg=min(len(signal), 256))

    # Compute geometric mean of PSD
    geometric_mean = np.exp(np.mean(np.log(psd + 1e-10)))

    # Compute arithmetic mean of PSD
    arithmetic_mean = np.mean(psd)

    # Calculate Spectral Flatness Measure
    sfm = geometric_mean / arithmetic_mean

    return sfm

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Stefan Ram on Fri Oct 25 17:00:14 2024
    ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
    marc nicole <mk1853387@gmail.com> wrote or quoted:
    I hope this question is not very far from the main topic of this list, but >>I have a hard time finding a way to check whether audio data samples are >>containing empty noise or actual significant voice/noise.
    The Spectral Flatness Measure (SFM), also called Wiener entropy, can
    separate the wheat from the chaff when it comes to how noise-like
    a signal is.

    You can also peep the envelope flatness (the flatness of the
    volume). If you've got some white noise that's not bringing much to
    the table, that envelope should be flatter than a pancake at IHOP.

    import librosa
    import numpy as np

    def measure_volume_flatness(audio_path, sr=None):
    # Load the audio file
    y, sr = librosa.load(audio_path, sr=sr)

    # Calculate the root mean square (RMS) energy for each frame
    frame_length = 2048
    hop_length = 512
    rms = librosa.feature.rms(y=y, frame_length=frame_length, hop_length=hop_length)[0]

    # Calculate the dynamic range
    db_range = librosa.amplitude_to_db(np.max(rms)) - librosa.amplitude_to_db(np.min(rms))

    # Normalize the dynamic range to a 0-1 scale
    # Assuming a maximum possible dynamic range of 120 dB
    flatness = 1 - (db_range / 120)

    return flatness

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)