【问题标题】:Average Amplitude (in dB) every second of audio file in LibrosaLibrosa 中音频文件每秒的平均幅度(以 dB 为单位)
【发布时间】:2021-03-11 06:36:45
【问题描述】:

我想获得每秒声音文件的平均幅度。例如0-1秒、1-2秒的平均幅度,以此类推。我尝试将采样率降低到 1,但在这种情况下,值会下降到 0。

import numpy as np 
import matplotlib.pyplot as plt 
from glob import glob
import librosa as lr

y, sr = lr.load(file,sr=10)
print(y)
print(len(y))
time = np.arange(0,len(y))/sr
print(len(time))
print(time,y)

print(y)
fig, ax = plt.subplots()
ax.plot(time,y)
ax.set(xlabel='Time(s)',ylabel='sound amplitude')
plt.show()

注意:我正在尝试以 dB 为单位获取幅度值。 Librosa 真的很新,如果有任何帮助,将不胜感激:)

【问题讨论】:

  • 你将如何定义 dB?
  • 你真的对第二个峰值感兴趣吗?
  • 是峰值应该能解决问题,

标签: python numpy librosa


【解决方案1】:

这将执行平均幅度,通常为 0。

y, sr = lr.load(file)
second = []
for s in range(0,len(y),sr):
    second.append( y[s:s+sr].mean() )

这将平均abs 幅度。

y, sr = lr.load(file)
second = []
for s in range(0,len(y),sr):
    second.append( np.abs(y[s:s+sr]).mean())

【讨论】:

  • 谢谢蒂姆的回答,让我检查一下,看看这是否解决了我的问题。
  • 您可能想尝试np.max,以获得峰值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-05
  • 1970-01-01
  • 2020-07-23
  • 1970-01-01
  • 1970-01-01
  • 2014-12-21
  • 1970-01-01
相关资源
最近更新 更多