pydub 多重淡入淡出效果后质量差

Bad quality after multiple fade effect with pydub

我想在某个时间生成带有背景音乐和说明的锻炼 mp3 文件(例如 "push harder"、"do another repetition !")

我用 pico2wave 生成​​指令,assemble 用 pydub 生成指令。

我这样做 :

for timing,phrase in phrases.items():
        fileToAdd = pydub.AudioSegment.from_file(rep+"/"+str(timing)+".wav")
        finalFile = finalFile.fade(to_gain=-35, start=(timing*1000)-500, duration=500) # on diminue la chanson, une demi seconde avant
        finalFile = finalFile.fade(to_gain=+35, start=(timing*1000)+len(fileToAdd), duration=500) 
        fichierFinal = fichierFinal.overlay(fileToAdd,position=timing*1000) 

结果文件质量很差。我尝试删除 "fade effect" 并且质量很好(但我听不太清楚 "instructions")

我该如何更改?我可以轻松制作淡出和淡入效果吗?

谢谢,

此致,

阿克塞尔

我认为问题在于您正在减弱音频然后再次增强它(因此每次衰减然后增强时您都会失去 35dB 的动态范围)。

我认为更好的解决方案是拆分音频并仅减少您需要的部分(无需任何增强操作)。

您在此处执行的操作有时称为 "ducking",因此我将在下面使用该名称:

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 听起来不错 :)