def Load filename aseg AudioSegment from_file filename format filename

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def Load(filename):
aseg = AudioSegment.from_file(filename, format=filename[-3::1]).set_channels(1)
aseg = aseg.set_frame_rate(16000)
samples = np.asarray(aseg.get_array_of_samples(), float) / aseg.max_possible_amplitude
volumes = np.clip(20 * np.emath.log10(np.abs(samples)), -70., 0.)
###################
target_loudness = -20.
meter = pyln.Meter(16000) # create BS.1770 meter
loudness = meter.integrated_loudness(samples)
delta_loudness = target_loudness - loudness
gain = np.power(10.0, delta_loudness / 20.0)
#########################
samples = gain * samples
return samples