当我尝试将长音频片段导出到mp3时,出现错误OSError: [Errno 22] Invalid argument
。最大可接受持续时间似乎在202到205分钟之间。错误和代码如下。
有没有办法能够导出超过205分钟的mp3?
compilation_audio.export(mp3_path, format = "mp3")
File "/usr/local/lib/python3.6/site-packages/pydub/audio_segment.py", line 612,
in export wave_data.writeframesraw(self._data)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 422,
in writeframesraw self._file.write(data)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tempfile.py", line 483,
in func_wrapper return func(*args, **kwargs)
OSError: [Errno 22] Invalid argument
这是代码。我使用here中的“Fur Elise”作为初始mp3文件。
202分钟段(“Fur Elise”重复69次)保存确定,205分钟段(“Fur Elise”重复70次)导出失败。
import os, pydub
audio_name = os.path.expanduser('~/Downloads/Fur Elise.mp3') # just under 3 min long
audio = pydub.AudioSegment.from_mp3(audio_name)
for compilation_audio in (audio * 69, audio * 70):
length_music = len(compilation_audio) / 60000.0
print("compilation_audio duration (min): " + str((length_music)))
mp3_path = os.path.expanduser('~/Downloads/compilation' + str(int(length_music)) + '.mp3')
compilation_audio.export(mp3_path, format = "mp3")
如果试图保存1000多分钟长的mp3(Fur Elise * 370),则会出现另一条错误消息:
compilation_audio.export(mp3_path, format = "mp3")
File "/usr/local/lib/python3.6/site-packages/pydub/audio_segment.py", line 612, in export
wave_data.writeframesraw(self._data)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 416, in writeframesraw
self._ensure_header_written(len(data))
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 457, in _ensure_header_written
self._write_header(datasize)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 474, in _write_header
self._sampwidth * 8, b'data'))
struct.error: 'L' format requires 0 <= number <= 4294967295
Exception ignored in: <bound method Wave_write.__del__ of <wave.Wave_write object at 0x1177e7cf8>>
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 316, in __del__
self.close()
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 434, in close
self._ensure_header_written(0)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 457, in _ensure_header_written
self._write_header(datasize)
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/wave.py", line 474, in _write_header
self._sampwidth * 8, b'data'))
struct.error: 'L' format requires 0 <= number <= 4294967295
答案 0 :(得分:1)
我认为这可能是Python中的错误!
有a related issue with no solution in the pydub repo。
我们也遇到了这个问题。
此issue in PyTorch具有类似的堆栈跟踪。他们确定问题出在lseek()
上。我不了解此修复程序,但可以找到似乎尚未解决的this issue in the Python bug tracker。问题似乎出在带符号的整数环绕,使得在某些情况下无法在大于2 ^ 63的文件中进行查找。