def compute_spectrograms(filename):
out_rate = 22050
frames, rate = librosa.load(filename, sr=out_rate, mono=True)
if len(frames) < out_rate:
# if less then 1 second - can't process
raise Exception("Audio duration is too short")
normalized_audio = _normalize(frames)
melspectr = librosa.feature.melspectrogram(y=normalized_audio, sr=out_rate, n_mels=N_MEL_BANDS, fmax=out_rate/2)
logmelspectr = librosa.logamplitude(melspectr**2, ref_power=1.0)
# now going through spectrogram with the stride of the segment duration
for start_idx in range(0, logmelspectr.shape[1] - SEGMENT_DUR + 1, SEGMENT_DUR):
yield logmelspectr[:, start_idx:start_idx + SEGMENT_DUR]
评论列表
文章目录