Skip to content

Instantly share code, notes, and snippets.

@okaysidd
Forked from gchavez2/cut_mp3.py
Created October 2, 2020 16:39
Show Gist options
  • Save okaysidd/af66509b63573c1f9a4707ad36184643 to your computer and use it in GitHub Desktop.
Save okaysidd/af66509b63573c1f9a4707ad36184643 to your computer and use it in GitHub Desktop.
Cut mp3 file with Python and pydub
# https://github.com/jiaaro/pydub
from pydub import AudioSegment
files_path = ''
file_name = ''
startMin = 9
startSec = 50
endMin = 13
endSec = 30
# Time to miliseconds
startTime = startMin*60*1000+startSec*1000
endTime = endMin*60*1000+endSec*1000
# Opening file and extracting segment
song = AudioSegment.from_mp3( files_path+file_name+'.mp3' )
extract = song[startTime:endTime]
# Saving
extract.export( file_name+'-extract.mp3', format="mp3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment