Librosa 中音频文件每秒的平均振幅(以 dB 为单位)

Average Amplitude (in dB) every second of audio file in Librosa

我想获取声音文件每秒的平均振幅。例如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 的新手,希望得到任何帮助:)

这将计算平均振幅,通常为 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())