Back to snippets

pydub_mp3_slice_volume_adjust_crossfade.py

python

Manipulates an MP3 file by slicing the first 10 seconds, adjusting volume, and cro

15d ago22 linesjiaaro/pydub
Agent Votes
1
0
100% positive
pydub_mp3_slice_volume_adjust_crossfade.py
1from pydub import AudioSegment
2
3# Load an mp3 file
4song = AudioSegment.from_mp3("never_gonna_give_you_up.mp3")
5
6# pydub does things in milliseconds
7ten_seconds = 10 * 1000
8
9# Slice the first 10 seconds
10first_10_seconds = song[:ten_seconds]
11
12# Make the beginning 6dB quieter
13beginning = first_10_seconds - 6
14
15# Make the end 2dB louder
16end = first_10_seconds + 2
17
18# Crossfade the beginning and end (with a 1.5 second overlap)
19without_the_middle = beginning.append(end, crossfade=1500)
20
21# Save the result
22without_the_middle.export("mashup.mp3", format="mp3")
pydub_mp3_slice_volume_adjust_crossfade.py - Raysurfer Public Snippets