-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_mp3.py
More file actions
43 lines (31 loc) · 1.54 KB
/
load_mp3.py
File metadata and controls
43 lines (31 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from pydub import AudioSegment
from pydub.playback import play
AUDIO_FILE: str = "./assets/vibe-on-173188.mp3";
OUTPUT_FILE: str = "./assets/vibe-on_export.wav";
LoadMP3 = lambda file_path: AudioSegment.from_mp3(file_path);
LoadWAV = lambda file_path: AudioSegment.from_wav(file_path);
INC_VOL = lambda audio, db: audio + db;
REP_AUD = lambda audio, rep: audio * rep;
FADE_IN_AUD = lambda audio, millisec: audio.fade_in(millisec);
EXPORT_AUD = lambda audio, file_path, expFormat: audio.export(file_path, format = expFormat);
def PlayAudio(audio_obj: AudioSegment, title: str="audio") -> None:
try:
print(f"Playing {title} ... \n(PRESS <ctrl+c> TO STOP)");
play(audio_obj);
except KeyboardInterrupt:
print(f"Stopping {title} ...\n");
def main() -> None:
print("Loading mp3 audio ...");
audio_mp3: AudioSegment = LoadMP3(AUDIO_FILE);
audio_mp3: AudioSegment = INC_VOL(audio_mp3, 6); # Increases the volume by 6dB
audio_mp3: AudioSegment = REP_AUD(audio_mp3, 2); # Repeate the clip 2 times
audio_mp3: AudioSegment = FADE_IN_AUD(audio_mp3, 2000); # Fade in for 2000 milisec
print("Converting mp3 to wav ...");
EXPORT_AUD(audio_mp3, OUTPUT_FILE, "wav");
print("Successfully converted");
print("Loading exported wav audio ...\n");
audio_wav: AudioSegment = LoadWAV(OUTPUT_FILE);
PlayAudio(audio_mp3, "Vibe ON");
PlayAudio(audio_wav, "Vibe ON EXPORTED");
if ("__main__" == __name__):
main();