我认为问题在于您将音频淡化然后再次增强它(因此每次衰减然后增强时您都会损失 35dB 的动态范围)。
我认为更好的解决方案是拆分音频并仅减少您需要的部分(不进行任何增强操作)。
您在此处执行的操作有时称为“闪避”,因此我将在下面使用该名称:
def duck(sound, position, duration, gain=-15.0, fade_duration=500):
"""
sound - an AudioSegment object
position - how many milliseconds into the sound the duck should
begin (this is where overlaid audio could begin, the fade down
will happen before this point)
duration - how long should the sound stay quiet (milliseconds)
gain - how much quieter should the sound get (in dB)
fade_duration - how long sound the fades last (in milliseconds)
"""
# this part is from the beginning until the end of the ducked section
first_part = sound[:position+duration]
first_part = first_part.fade(to_gain=gain, end=position, duration=fade_duration)
# this part begins where the fade_up happens (will just fade in)
second_part = sound[position+duration:]
second_part = second_part.fade(from_gain=gain, start=0, duration=fade_duration)
return first_part + second_part
for timing, phrase in phrases.items():
fileToAdd = pydub.AudioSegment.from_file(rep+"/"+str(timing)+".wav")
finalFile = duck(finalFile, position=timing*1000, duration=len(fileToAdd))
finalFile = finalFile.overlay(fileToAdd, position=timing*1000)
经过一些测试,35dB 可能比你想要的要多。15dB 对我来说听起来不错:)