forked from xiaoxiae/videos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize
executable file
·35 lines (20 loc) · 830 Bytes
/
normalize
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
#!/bin/python3
"""A script for normalizing the recorded voicelines."""
import os
import argparse
import soundfile as sf
import pyloudnorm as pyln
from glob import glob
audio_directory = "audio"
parser = argparse.ArgumentParser()
os.chdir(os.path.dirname(os.path.abspath(__file__)))
arguments = parser.parse_args()
raw_directory = os.path.join(audio_directory, "raw")
normalized_directory = os.path.join(audio_directory, "normalized")
for path in glob(os.path.abspath(os.path.join(raw_directory, "*.wav"))):
name = os.path.basename(path)
data, rate = sf.read(path)
meter = pyln.Meter(rate)
loudness = meter.integrated_loudness(data)
loudness_normalized_audio = pyln.normalize.loudness(data, loudness, -25.0)
sf.write(os.path.join(normalized_directory, name), loudness_normalized_audio, rate)