首页 > 解决方案 > 关于 librosa.load 和 scipy.io.wavfile.read 返回的数据类型的混淆

问题描述

我是音频处理的新手,我的项目需要一些帮助。有人可以解释一下 librosa.load 和 scipy.io.wavefile.read 返回的数据类型之间的区别吗?前者给出一个浮点数组,而后者给出一个整数数组。有趣的是,两种情况下返回的数组的大小是不同的。

请对此提供一些见解。(您可以使用自己的音频文件来重现问题)

sig, sr = librosa.core.load(filepath, sr=None)
sig[:10]
array([ 0.00262944,  0.00108277, -0.00248273, -0.00865669, -0.0161767 ,
   -0.01958228, -0.01867038, -0.01742653, -0.01652605, -0.01589082],
  dtype=float32)

sr, y = scipy.io.wavfile.read(filepath)
y[:10]
array([  94,  -10, -217, -564, -627, -582, -527, -520, -440, -349],
  dtype=int16)

print(sig.shape)
(7711,)

y.shape
(5595,)

标签: pythonscipyaudio-processinglibrosa

解决方案


再看一下librosa.core.load. 它在前三句话中说:

Load an audio file as a floating point time series.

Audio will be automatically resampled to the given rate (default sr=22050).

To preserve the native sampling rate of the file, use sr=None.

librosa将数据转换为浮点数也是如此,并且(默认情况下)将数据重新采样为每秒 22050 个样本。你用过sr=None,所以我不知道为什么数组的长度会不同。


推荐阅读