构建频谱处理函数
代码如下:
def log_specgram(audio, sample_rate, window_size=20, step_size=10, eps=1e-10):
np
erseg = int(round(window_size sample_rate / 1e3))
noverlap = int(round(step_size samplerate / 1e3))
freqs, , spec = signal.spectrogram(audio,
fs=sample_rate,
window='hann',
nperseg=nperseg,
noverlap=noverlap,
detrend=False)
return freqs, np.log(spec.T.astype(np.float32) + eps)