Skip to content

Instantly share code, notes, and snippets.

@kkabdol
Created December 18, 2018 00:39
Show Gist options
  • Select an option

  • Save kkabdol/eeab160763e017e70894d05e6da42569 to your computer and use it in GitHub Desktop.

Select an option

Save kkabdol/eeab160763e017e70894d05e6da42569 to your computer and use it in GitHub Desktop.
Shortening audio files
import os
from pydub import AudioSegment // https://github.com/jiaaro/pydub
source_dir = "C:\Users\schoe\Desktop\Jukebox\source\\"
destination_dir = "C:\Users\schoe\Desktop\Jukebox\destination\\"
for file in os.listdir(source_dir):
milliseconds = 10*1000
print( "split \"" + file + "\" from " + source_dir + " into " + destination_dir + " by " + "{:,}".format( milliseconds / 1000 ) + " seconds." )
song = AudioSegment.from_wav( source_dir + file )
split = song[:milliseconds]
split.export( destination_dir + file , format="wav")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment