Skip to content

Instantly share code, notes, and snippets.

@OSoG
Forked from gchavez2/cut_mp3.py
Created February 9, 2019 20:16
Show Gist options
  • Select an option

  • Save OSoG/d6399d2fa219f9d62cdd337b8665744b to your computer and use it in GitHub Desktop.

Select an option

Save OSoG/d6399d2fa219f9d62cdd337b8665744b 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