Python wave 读取帧不会返回窗口上的所有帧



我正在尝试使用 wave 模块从 wave 文件中获取字节字符串:

import wave
wavfile = open(filename)
w = wave.open(wavfile)
print "nsamples:", w.getnframes()
print "sample size:", w.getsampwidth()
print "channels:", w.getnchannels()
data = w.readframes(w.getnframes())
print "number of samples read:", len(data) / (w.getsampwidth() * w.getnchannels())

在Unix系统上,使用Anaconda安装,这有效(对于任何给定的波文件):

nsamples: 4800000
sample size: 3
channels: 1
number of samples read: 4800000

但是,在同样使用 Anaconda 安装的 Windows 系统上,这不起作用(对于任何给定的 wavefile):

nsamples: 4800000
sample size: 3
channels: 1
number of samples read: 443
读取的 443 个样本

等于 4800000 的前 443 个样本。有什么想法吗?

找到了解决方案,这不是 wave 模块的问题:

wavfile = open(filename, 'rb')

根据:Python不会读取整个文本文件

最新更新