首页 > 解决方案 > Librosa中音频文件每秒的峰值频率

问题描述

我正在尝试通过 Librosa 获取音频文件每秒的峰值频率值。我真的是 Librosa 的新手,真的会得到任何帮助。试过这段代码,但还没有结果。

y, sr = librosa.load(file, sr=None)
# short time fourier transform
# (n_fft and hop length determine frequency/time resolution)
n_fft = 2048
S = librosa.stft(y, n_fft=n_fft, hop_length=n_fft//2)
# convert to db
# (for your CNN you might want to skip this and rather ensure zero mean and unit variance)
D = librosa.amplitude_to_db(np.abs(S), ref=np.max)
# average over file
D_AVG = np.mean(D, axis=1)

plt.bar(np.arange(D_AVG.shape[0]), D_AVG)
x_ticks_positions = [n for n in range(0, n_fft // 2, n_fft // 16)]
x_ticks_labels = [str(sr / 2048 * n) + 'Hz' for n in x_ticks_positions]

标签: pythonlibrosa

解决方案


推荐阅读