I'm trying to create an audio wave file over 4GB in my python script but I get an error. Here is a short script reproducing the problem. Can someone tell me why I got such an error and how to fix it, or if it might be a bug?
I tried with python 2.7 and 3.4, but got the same error with both.
# script for python 2
import wave
# create a large (>4gb) file
wf = wave.open("foo.wav", "w")
wf.setnchannels(2)
wf.setsampwidth(2)
wf.setframerate(44100)
text = 'a' * 1024**2
for i in xrange(5 * 1024):
print i
wf.writeframes(text)
wf.close()
The output:
4088
4089
4090
4091
4092
4093
4094
4095
Traceback (most recent call last):
File "test.py", line 16, in <module>
wf.writeframes(text)
File "/usr/lib/python2.7/wave.py", line 444, in writeframes
self._patchheader()
File "/usr/lib/python2.7/wave.py", line 496, in _patchheader
self._file.write(struct.pack('<L', 36 + self._datawritten))
struct.error: 'L' format requires 0 <= number <= 4294967295
Exception struct.error: "'L' format requires 0 <= number <= 4294967295" in <bound method Wave_write.__del__ of <wave.Wave_write instance at 0x7fed4ed58908>> ignored