使用 pydub 修剪音频文件返回空文件

问题描述 投票:0回答:1

我看到了关于同一问题的另一篇文章,但它对我没有帮助。我有这个代码

from pydub import AudioSegment

path = input("Enter path of mp3 file")
song = AudioSegment.from_mp3(path)
start = input("At which second shall the new file begin?")
start = int(start)*1000
end = input("At which second shall the new file end?")
end = int(end)*1000
newmp3 = song[start:end]
path = path[:-5]
newmp3.export(str(path)+"n.mp3", format = "mp3")
print("New Audio File is created and saved")

结果它向我的文件夹添加了一个空的 mp3。为什么?我的错误在哪里?

python mp3 pydub
1个回答
0
投票

您的变量名称有拼写错误:

path = input("Enter path of mp3 file")
song = AudioSegment.from_mp3(path)
© www.soinside.com 2019 - 2024. All rights reserved.