gpt4 book ai didi

Python - Wave 文件超过 4gb : struct. 错误: 'L' 格式需要 0 <= 数字 <= 4294967295

转载 作者:太空狗 更新时间:2023-10-30 01:01:15 24 4
gpt4 key购买 nike

我试图在我的 python 脚本中创建一个超过 4GB 的音频波形文件,但出现错误。这是一个重现问题的简短脚本。谁能告诉我为什么会出现这样的错误以及如何修复它,或者它是否可能是一个错误?

我尝试使用 python 2.7 和 3.4,但两者都出现了同样的错误。

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

输出:

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

最佳答案

.wav 文件不能大于 4GB,因为 wave 文件格式规范不允许这样做。正如维基百科上所解释的:

The WAV format is limited to files that are less than 4 GB, because of its use of a 32-bit unsigned integer to record the file size header.

另见 issue 16461在 Python 中,它将限制从 2GB 增加到 4GB(但仅此而已)。

关于Python - Wave 文件超过 4gb : struct. 错误: 'L' 格式需要 0 <= 数字 <= 4294967295,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27880302/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com