def mel_spectrum(power_spectrum: np.ndarray,
mel_fbank: np.ndarray = None,
fs: int = None,
window_width: int = None,
n_filt: int = 40) -> np.ndarray:
"""
Computes a Mel spectrogram from the specified power spectrogram.
Optionally, precomputed Mel filter banks can be passed to this function, in which case the n_filt, fs, and
window_width parameters are ignored. If precomputed Mel filter banks are used, the caller has to ensure that they
have correct shape.
Parameters
----------
power_spectrum: numpy.ndarray
The power spectrogram from which a Mel spectrogram should be computed
mel_fbank: numpy.ndarray, optional
Precomputed Mel filter banks
fs: int
Sampling frequency of the signal from which the power spectrogram was computed. Ignored if precomputed Mel
filter banks are used.
window_width: int
Window width in samples that was used to comput the power spectrogram. Ignored if precomputed Mel filter banks
are used.
n_filt: int
Number of Mel filter banks to use. Ignored if precomputed Mel filter banks are used.
Returns
-------
numpy.ndarray
Mel spectrogram computed from the specified power spectrogram
"""
if mel_fbank is None:
_, mel_fbank = mel_filter_bank(fs, window_width, n_filt)
filter_banks = np.dot(mel_fbank, power_spectrum)
return filter_banks
评论列表
文章目录