gpt4 book ai didi

python - python中的pydub错误

转载 作者:行者123 更新时间:2023-12-04 18:09:54 27 4
gpt4 key购买 nike

我已经成功导入了pydub但对于代码:

from pydub import AudioSegment
song = AudioSegment.from_mp3("c:\mks.mp3")
first_ten_seconds = song[:10000]
song.export("d:\mks.mp3", format="mp3")

但它给出了以下错误:

python "C:\Users\mKs\Desktop\mks2.py"
Process started >>>
Traceback (most recent call last):
File "C:\Users\mKs\Desktop\mks2.py", line 2, in <module>
song=AudioSegment.from_mp3("c:\mks.mp3");
File "C:\Python27\lib\site-packages\pydub-0.5.2-py2.7.egg\pydub\audio_segment.py", line 194, in from_mp3
return cls.from_file(file, 'mp3')
File "C:\Python27\lib\site-packages\pydub-0.5.2-py2.7.egg\pydub\audio_segment.py", line 189, in from_file
return cls.from_wav(output)
File "C:\Python27\lib\site-packages\pydub-0.5.2-py2.7.egg\pydub\audio_segment.py", line 206, in from_wav
return cls(data=file)
File "C:\Python27\lib\site-packages\pydub-0.5.2-py2.7.egg\pydub\audio_segment.py", line 33, in __init__
raw = wave.open(StringIO(data), 'rb')
File "C:\Python27\lib\wave.py", line 498, in open
return Wave_read(f)
File "C:\Python27\lib\wave.py", line 163, in __init__
self.initfp(f)
File "C:\Python27\lib\wave.py", line 128, in initfp
self._file = Chunk(file, bigendian = 0)
File "C:\Python27\lib\chunk.py", line 63, in __init__
raise EOFError
EOFError

我很乐意就此主题获得帮助

最佳答案

我在您的代码中看到的唯一问题是尾随“;”在最后 3 行的末尾。请删除那些,看看您是否仍然收到错误。

此外,请确保您有 ffmpeg ( http://www.ffmpeg.org/ ) 安装。它是支持所有非 wav 文件格式所必需的。

已添加:

我认为您在 python 安装中破坏了模块依赖性。我已经尝试过您在上面使用 python 2.7.2 提供的代码。它对我来说很好:

>>> from pydub import AudioSegment
>>> song = AudioSegment.from_wav('goodbye.wav')
>>> first_ten_seconds = song[:10000]
>>> song.export('goodbye1.wav',format='wav')
<open file 'goodbye1.wav', mode 'wb+' at 0x10cf2b270>

关于python - python中的pydub错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16897392/

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