trimming audio file with pydub returns empty file

55 Views Asked by At

I saw another post on the same problem but it didn't help me. I have this code

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

The result it that it adds an empty mp3 to my folder. Why? Where is my mistake?

1

There are 1 best solutions below

2
jordanlv On

There is a typo in your variable names :

path = input("Enter path of mp3 file")
song = AudioSegment.from_mp3(path)