在此示例中,为什么在librosa.core.stft中将window_length / hop_length与采样率相乘?

问题描述

我是语音识别的新手,我正在讲this implementation中有关说话者验证的详细信息。在data_preprocess.py中,作者使用librosa库。这是代码的简化版本:

def preprocess_data(data_dir,res_dir,N,M,tdsv_frame,sample_rate,nfft,window_len,hop_len):
    os.makedirs(res_dir,exist_ok=True)
    batch_frames = N * M * tdsv_frame
    batch_number = 0
    batch = []
    batch_len = 0
    for i,path in enumerate(tqdm(os.listdir(data_dir))):
        data,sr = librosa.core.load(os.path.join(data_dir,path),sr=sample_rate)
        S = librosa.core.stft(y=data,n_fft=nfft,win_length=int(window_len * sample_rate),hop_length=int(hop_len * sample_rate))
        batch.append(S)
        batch_len += S.shape[1]
        if batch_len < batch_frames: continue
        batch = np.concatenate(batch,axis=1)[:,:batch_frames]
        np.save(os.path.join(res_dir,"voice_%d.npy" % batch_number),batch)
        batch_number += 1
        batch = []
        batch_len = 0


N = 2               # number of speakers of batch
M = 400             # number of utterances per speaker
tdsv_frame = 80     # feature size
sample_rate = 8000  # sampling rate
nfft = 512          # fft kernel size
window_len = 0.025  # window length (ms)
hop_len = 0.01      # hop size (ms)
data_dir = "./data/clean_testset_wav/"
res_dir = "./data/clean_testset_wav_prep/"

他们希望根据论文中的图形创建一批(N*M)*tdsv_frame大小的特征。

enter image description here

我想我了解window_length,hop_length的概念,但是对我来说,一个问题是作者如何设置这些参数。为什么要像在这里这样用sample_rate增加这些长度:

S = librosa.core.stft(y=data,hop_length=int(hop_len * sample_rate))

谢谢。

解决方法

librosa.core.stft的样本数为win_length / hop_length。这对于数字信号处理来说很典型,因为从根本上说,系统是基于每秒采样数(采样率)是离散的。

但是,为了便于人类理解,以秒/毫秒为单位来考虑这些时间更有意义。如您的示例

window_len = 0.025  # window length (ms)
hop_len = 0.01      # hop size (ms)

因此,要从几秒钟的时间变为采样数量的时间,必须乘以采样率。

,

window_len 和 hop_len 的单位是(ms),但是在 librosa 中应该是样本数。

样本数 = 采样率 * (ms)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...