-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNormalize.py
More file actions
31 lines (26 loc) · 985 Bytes
/
Copy pathNormalize.py
File metadata and controls
31 lines (26 loc) · 985 Bytes
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
# Import libraries
from pydub import AudioSegment, effects
import os.path
import gc
# Determine main program directory
maindirectory = os.path.dirname(os.path.abspath(__file__)) # The absolute path to this file
directory= os.path.join(maindirectory,"DownloadedSongs")
try:
music_dict = [x for x in os.listdir(directory) if ".ogg" or ".OGG" or ".Ogg" in x]
music_count = len(music_dict)
except FileNotFoundError:
print("[WARN] Directory not found. Exiting ...")
quit()
counter = 1
for file in music_dict:
print(f"[INFO] ({counter}/{music_count}) Normalizing {file}.")
rawsound = AudioSegment.from_file(maindirectory + "/DownloadedSongs/" + str(file), "ogg")
normalizedsound = effects.normalize(rawsound)
normalizedsound.export(maindirectory + "/DownloadedSongs/" + str(file), format="ogg")
rawsound.close()
normalizedsound.close()
del rawsound
del normalizedsound
gc.collect() # Free memory
counter += 1
print("Success!")