我目前正在尝试创建一个用于深度学习的大型数据集,其中包含大量存储在一起的压缩mp3文件,这样我就不需要单独加载10万个文件。
x = b''
with open("file1.mp3", "rb") as f:
x += f.read()
print(len(x)) # 362861
with open("file2.mp3", "rb") as f:
x += f.read()
print(len(x)) # 725722
with open("testdataset", 'wb+') as f:
f.write(x)
现在我想一个接一个地加载:
with open("testdataset", 'rb') as f:
bs = f.read(362861)
y, sr = librosa.core.load(io.BytesIO(bs), mono=True, sr=44100, dtype=np.float32) # crahes
它会中断,并显示以下错误:
RuntimeError: Error opening <_io.BytesIO object at 0x7f509ed1cf90>: File contains data in an unknown format.
为了测试,我尝试加载原始文件,它工作得很好:
y, sr = librosa.core.load("file1.mp3", mono=True, sr=44100, dtype=np.float32) # works fine
请注意,原始mp3的这个“虚拟”-load也会抛出一个警告:
UserWarning: PySoundFile failed. Trying audioread instead. warnings.warn('PySoundFile failed. Trying audioread instead.')
为什么会发生这种情况?有没有一种更好的方法将许多独立的文件存储在一起并一次加载它们?
以下是我正在使用的版本:
python: 3.8.3 (default, May 14 2020, 20:11:43)
[GCC 7.5.0]
librosa: 0.7.2
audioread: 2.1.8
numpy: 1.19.0
scipy: 1.5.0
sklearn: 0.23.1
joblib: 0.15.1
decorator: 4.4.2
six: 1.15.0
soundfile: 0.10.3
resampy: 0.2.2
numba: 0.48.0
发布于 2021-06-23 18:57:23
librosa
使用不支持mp3文件的soundfile
https://stackoverflow.com/questions/62601346
复制相似问题