Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

Audio volume normalize python

I have multiple wave files, some are small volume and others are large volume.

I want to "Normalize" sound amplitude.

(Like the "Normalize" function that Some audio sequencer application has. Making volume bigger to the peak comes to the 0db.)

For example librosa library, it has librosa.util.normalize, however I am not sure it is what I meant.

I want to align the volume of audio, is there any practice?

question from:https://stackoverflow.com/questions/66066364/audio-volume-normalize-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Find the maximum peak (positive or negative, so use abs) in any channel. For instance in a 16 bits file, imagine you find 25000. Compute the ratio of that value relatively to the maximum in the signed 16 bit range and invert it :

ratio = 32767.0 / 25000 #(equivalent to 1 / (25000 / 32767.0))

Now iterate all samples and multiply them by the inverted ratio so that 25000 becomes 32767 :

for(sample in samples):
    sample = round(sample * ratio)

This operation is called "normalization" or "optimization" depending on the software.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...