Sujet : Re: How to check whether audio bytes contain empty noise or actual voice/signal?
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 25. Oct 2024, 18:43:11
Autres entêtes
Organisation : Stefan Ram
Message-ID : <noise-20241025174236@ram.dialup.fu-berlin.de>
References : 1 2
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