Skip to content

Instantly share code, notes, and snippets.

@comzeradd
Created June 7, 2015 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comzeradd/31e4a1998187e16541e8 to your computer and use it in GitHub Desktop.
Save comzeradd/31e4a1998187e16541e8 to your computer and use it in GitHub Desktop.
Random playlist with crossfaded tracks
import random
from glob import glob
from pydub import AudioSegment
playlist_songs = [AudioSegment.from_mp3(mp3_file) for mp3_file in glob("*.mp3")]
random.shuffle(playlist_songs)
playlist = playlist_songs.pop(0)
for song in playlist_songs:
playlist = playlist.append(song, crossfade=(15 * 1000))
playlist = playlist.fade_out(15)
playlist_length = len(playlist) / (1000*60)
out_f = open("%s_minute_playlist.mp3" % playlist_length, 'wb')
playlist.export(out_f, format='mp3')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment