python - 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]
解决方案
推荐阅读
- java - Jackson 自定义序列化器
- javascript - 如何在单击复选框时改进和评估 var 并修改对象属性?
- javascript - ReactJS 中的 DOM 操作和页面重新加载
- python - 对于数据帧中的每个 lat,lng 循环通过另一个数据帧并进行比较
- java - 如何在 Spring Boot 中使用 KeyHolder?
- selenium-webdriver - 如何在不传递selenium java中的元素的情况下实现wait()
- java - 如何优雅地解析字符串以获得您所需要的?
- java - 如何为线条绘制形状制作圆形破折号或圆点
- java - 什么解析策略最适合 Http 消息?
- c# - 自动选择下拉列表中的一项 asp.net c#