Python - Wave file over 4gb: struct.error: format L requires 0 <= number <= 4294967295

I am trying to create an audio wave file larger than 4 GB in my python script, but I am getting 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 could be an error?

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

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
+4
source share
1 answer

.wav files cannot exceed 4 GB, as the wave file format specification prevents this. As explained on Wikipedia:

WAV 4 - 32- .

. issue 16461 Python, 2 4 ( ).

+5

Source: https://habr.com/ru/post/1570720/


All Articles