Librosa的采样率问题 [英] Sampling rate issue with Librosa

查看:160
本文介绍了Librosa的采样率问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行STFT时,然后在具有库

When doing a STFT, and then an inverse STFT (iSTFT) on a 16 bits 44.1 khz audio file with the library Librosa :

import librosa

y, sr = librosa.load('test.wav', mono=False)
y1 = y[0,]
S = librosa.core.stft(y1)
z1 = librosa.core.istft(S, dtype=y1.dtype)
librosa.output.write_wav('test2.wav', z1, sr)

the output is only a 22 khz audio file. Why? Where is there the sampling rate change in librosa ?

解决方案

The librosa.load() function enables target sampling, wherein the audio file you import can be re-sampled to the target sample rate specified by the keyword argument sr.

If you want to use the original sample rate, you have to explicitly set the the target sample rate to None: sr=None. By default, sr=22050, which is why your output is ~22khz.

By way of example:

Default Setting - sub-sampling to default 22,050 Hz

In[51]: filename = librosa.util.example_audio_file()
In[52]: y1, sr1 = librosa.load(filename)
In[53]: print sr1
22050

Explicitly Setting sr=None ensures original sampling preserved

In[54]: y2, sr2 = librosa.load(filename,sr=None)
In[55]: print sr2
44100

Sub-sampling to a specified rate, 16,000 Hz

In[56]: y3, sr3 = librosa.load(filename,sr=16000)
In[57]: print sr3
16000

The result:

这篇关于Librosa的采样率问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆