Search code examples
pythonwindowswavwave

Python wave readframes doesn't return all frames on windows


I'm trying to get the byte string from a wavefile with the wave module:

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())

On Unix systems, using the Anaconda installation, this works (for any given wavefile):

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

However on Windows systems, also using the Anaconda installation, this doesn't work (for any given wavefile):

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

The 443 samples read are equal to the first 443 samples of the 4800000. Any ideas?


Solution

  • Found the solution, it wasn't an issue with the wave module:

    wavfile = open(filename, 'rb')
    

    as per: Python Does Not Read Entire Text File