voice-recognition - 为什么在这个例子中,window_length/hop_length 与 librosa.core.stft 中的采样率相乘?
问题描述
我是语音识别的新手,我将详细介绍说话人验证的实现。在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
.
我想我理解 window_length、hop_length 的概念,但对我来说问题是作者如何设置这些参数。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))
谢谢你。
解决方案
librosa.core.stft
以样本数取 win_length/hop_length。这对于数字信号处理来说是典型的,因为从根本上说,系统是基于每秒的样本数(采样率)而离散的。
然而,为了便于人类理解,以秒/毫秒为单位考虑这些时间更有意义。如你的例子
window_len = 0.025 # window length (ms)
hop_len = 0.01 # hop size (ms)
因此,要从以秒为单位的时间到以样本数量为单位的时间,必须乘以采样率。
推荐阅读
- python - 通过匹配列名选择列
- node.js - 在 docker Selenium_Hub、Selenium-Node-Chrome-Debug 和带有 Mocha + Selenium-Webdriver (JS) 的容器中运行测试时无法上传文件
- html - 将字体规范从 Adobe XD 复制到 html/css
- python - 请帮助我使用python
- sql - SQL UNION ALL 查询返回日期字段中的所有 Null 值
- scala - Spark Dataframe 到 TXT 文件没有回车
- c# - 如何在 LINQ 中思考条件
- gmail-api - 是否可以使用 gmail -API 从一个特定发件人处获取最近的 5 封电子邮件
- pyarrow - 如何在 python 中使用 pyarrow 读取 csv 文件
- ruby - 不使用“.length”或“.size”方法的字符串计数?