@register_pydub_effect defnormalize(seg, headroom=0.1):# 传入一个pydub的AudioSegment对象<class 'pydub.audio_segment.AudioSegment'> """ headroom is how close to the maximum volume to boost the signal up to (specified in dB) headroom是多远接近最大音量(振幅)以提升信号(以dB为单位) """ peak_sample_val = seg.max# 计算传入的sound的最大振幅作为 峰值样本振幅值
# if the max is 0, this audio segment is silent, and can't be normalized # 如果最大值为0,则此音频段是静默的,无法标准化 直接返回seg就好 if peak_sample_val == 0: return seg