我在将样本数组转换为分贝时遇到问题。这是我尝试过的代码。
from pydub import AudioSegment
audio=AudioSegment.from_mp3('am_voice.mp3')
samples=audio.get_array_of_samples()
import math
def convert_to_decibel(arr):
if arr!=0:
return 10 * math.log10(abs(arr))
else:
return -60
data=[convert_to_decibel(i) for i in samples]
Run Code Online (Sandbox Code Playgroud)
这将返回所有正数据。然而,分贝值应始终为负值。这是我要创建的数据:
percentile=np.percentile(data,[25,50,75])
print(f"1st Quartile : {percentile[0]}")
print(f"2nd Quartile : {percentile[1]}")
print(f"3rd Quartile : {percentile[2]}")
print(f"Mean : {np.mean(data)}")
print(f"Median : {np.median(data)}")
print(f"Standard Deviation : {np.std(data)}")
print(f"Variance : {np.var(data)}")
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
PS:我也尝试过 librosa 和其他库。