【问题标题】:Librosa melspectrogram times don't match actual times in audio fileLibrosa melspectrogram 时间与音频文件中的实际时间不匹配
【发布时间】:2020-02-09 18:05:11
【问题描述】:

我正在尝试使用 librosa.feature 计算 MFCC 系数,但是当我使用 specshow 绘制它时,specshow 图表上的时间与我的音频文件中的实际时间不匹配

我尝试了 librosa 文档https://librosa.github.io/librosa/generated/librosa.feature.mfcc.html 中的代码 我们创建了具有预先计算的对数功率梅尔谱图的 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 样本开始,也就是 10ms,但不是

【问题讨论】:

    标签: python librosa


    【解决方案1】:

    您应该在使用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中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-08
      • 2021-08-22
      • 1970-01-01
      相关资源
      最近更新 更多