Skip to content

Instantly share code, notes, and snippets.

@Raudcu
Forked from gchavez2/cut_mp3.py
Created June 11, 2020 17:33
Show Gist options
  • Save Raudcu/4489fecd388428425d7c43e672633db0 to your computer and use it in GitHub Desktop.
Save Raudcu/4489fecd388428425d7c43e672633db0 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