python - 关于 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,)
解决方案
再看一下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
,所以我不知道为什么数组的长度会不同。
推荐阅读
- javascript - 使用 css 和 js 在点击时切换图像信息
- javascript - 数据加载后如何将base64数据添加到图像中?(在反应本机中)
- video-streaming - 如何让 Animate CC 播放托管视频?
- c# - 在 asp.net 中如何知道从哪个站点用户被重定向到我们的站点?
- java - 从用户输入中获取元素数量?
- javascript - 更改动态填充表中列的背景颜色 onClick
- python - Python 的 re.findAll() 函数无法按预期工作
- php - 继续浏览而不等待输出到 php
- javascript - 未捕获的类型错误:无法读取未定义的属性“webpackHotUpdate”
- r - units::set_units() 无法识别变量中的单位