Librosa melspectrogram时间与音频fi中的实际时间不匹配

2024-10-03 15:30:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着用librosa.feature功能,但当我使用specshow绘制时,specshow图形上的时间与音频文件中的实际时间不匹配

我试过librosa文档中的代码https://librosa.github.io/librosa/generated/librosa.feature.mfcc.html 在这里,我们创建具有预先计算的对数功率Mel谱图的MFCC

WINDOW_HOP = 0.01       # [sec]
WINDOW_SIZE = 0.025     # [sec]

y, fs = librosa.load('audio_dataset/0f39OWEqJ24.wav', sr=None) # fs is 22000

# according to WINDOW_SIZE and fs, win_length is 550, and hop_length is 220
mel_specgram = librosa.feature.melspectrogram(y[:550], sr=fs, n_mels=20, hop_length=int(WINDOW_HOP * fs), win_length=int(WINDOW_SIZE * fs))

mfcc_s = librosa.feature.mfcc(S=librosa.power_to_db(mel_specgram), n_mfcc=12)

librosa.display.specshow(mfcc_s, x_axis='s')

现在看一下specshow图像中的比例,第二帧(窗口)应该从220 sample开始,也就是10ms,但它不是enter image description here


Tags: andtosizeis时间secwindowfs
1条回答
网友
1楼 · 发布于 2024-10-03 15:30:25

使用specshowlibrosa.feature.mfcc时,应指定采样率。否则假定22050 Hz。另外,告诉librosa,你使用了哪种跳跃长度:

[...]
hop_length = int(WINDOW_HOP * fs)
mel_specgram = librosa.feature.melspectrogram(y[:550], sr=fs,
    n_mels=20, hop_length=hop_length,
    win_length=int(WINDOW_SIZE * fs))

mfcc_s = librosa.feature.mfcc(S=librosa.power_to_db(mel_specgram), n_mfcc=12, sr=fs)

librosa.display.specshow(mfcc_s, x_axis='s', sr=fs, hop_length=hop_length)

这些细节对于正确的可视化是必不可少的,而不是包含在mfcc_s中的。你知道吗

相关问题 更多 >