我正在尝试从位于桶中的tarfile读取wav文件。因为有很多文件,我不想先提取这些文件
相反,我希望从tar文件读取数据并将其流式传输到wavfile.read
(从scipy.io
)
with tf.gfile.Open(chunk_fp, mode='rb') as f:
with tarfile.open(fileobj=f, mode='r|*') as tar:
for member in ds_text.index.values:
bytes = BytesIO(tar.extractfile(member)) # Obviously not working
rate, wav_data = wavfile.read(bytes)
# Do stuff with data ..
然而,我无法得到一个供wavfile.read
工作的蒸汽
尝试不同的事情会导致不同的错误:
tar.extractfile(member).seek(0)
{AttributeError}'_Stream' object has no attribute 'seekable'
tar.extractfile(member).raw.read()
{StreamError}seeking backwards is not allowed
等等
有什么办法可以做到这一点吗
结果证明我只是在错误的模式下打开了文件。使用
r:*
而不是r|*
可以:相关问题 更多 >
编程相关推荐