Created
February 11, 2020 23:11
-
-
Save Wikinaut/b9c465cc6f5743c2647d4162631035a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from glob import glob | |
| from pydub import AudioSegment | |
| i = 0 | |
| for name in sorted(glob("*.mp3")): | |
| i = i+1 | |
| print str(i)+" "+name | |
| playlist_songs = [AudioSegment.from_mp3(mp3_file) for mp3_file in sorted(glob("*.mp3"))] | |
| print "Number of songs. "+str(len(playlist_songs)) | |
| for i in range(0, len(playlist_songs)): | |
| songcut = playlist_songs.pop(0) | |
| # songcut = songx[:30*1000] | |
| print i | |
| if i == 0: | |
| playlist = songcut | |
| else: | |
| # We don't want an abrupt stop at the end, so let's do a 10 second crossfades | |
| playlist = playlist.append(songcut, crossfade=(10 * 1000)) | |
| # let's fade out the end of the last song | |
| # playlist = playlist.fade_out(30) | |
| # hmm I wonder how long it is... ( len(audio_segment) returns milliseconds ) | |
| playlist_length = len(playlist) / (1000*60) | |
| # lets save it! | |
| with open("%s_minute_playlist.mp3" % playlist_length, 'wb') as out_f: | |
| playlist.export(out_f, format='mp3') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment