Exemple #1
0
 def load_tracks(self, filenames):
     """Loads files as pydub tracks"""
     app = self.parent.parentApp
     tracks = []
     for filename in filenames:
         app.notify('Loading {title}...'.format(title=filename))
         track = audio.load(filename)
         if not app._already_cut:
             track = audio.cut(track, app._track_length * 2)
         tracks.append(track)
     return tracks
Exemple #2
0
def overlay_music(track):
    """Adds another song layer"""
    if not _OVERLAY_TRACKS:
        return track
    overlay_track = random.choice(_OVERLAY_TRACKS)
    # Cut overlay track to track's length
    track_length = len(track)
    if len(overlay_track) > track_length:
        overlay_track = audio.cut(
            overlay_track,
            track_length,
            0,
            len(overlay_track) - track_length,
        )
    if track.max > overlay_track.max:
        overlay_track += 3
    # Lower volume of our track
    track -= config.OVERLAY_VOLUME_DECREASE
    return audio.overlay([track, overlay_track])
Exemple #3
0
    'Output directory (will be created if not present): [./tracks]'
) or './tracks'
length = input('Track length, in seconds: [70] ') or 70
length = int(length)

if not os.path.exists(output_dir):
    os.mkdir(output_dir)

filenames = utils.get_filenames(input_dir)
filenames_length = len(filenames)
for i, filename in enumerate(filenames.values(), start=1):
    pretty_print(
        'Converting file {i}/{total}... [{filename}]'.format(
            i=i,
            total=filenames_length,
            filename=os.path.basename(filename),
        ),
    )
    track = audio.load(filename)
    track = audio.cut(track, length * 1000)
    new_filename = os.path.join(
        output_dir,
        os.path.basename(filename),
    )
    track.export(new_filename, format='mp3', bitrate='256k')
    # Copy metadata, too
    data = EasyID3(filename)
    data.save(new_filename, v1=2)
print()
print('Done.')