如何在Python中实现声音淡入??

如何在Python中实现声音淡入??,python,Python,def淡入snd,淡入长度: “为该波形文件进行声音淡入” new_snd=sound.copysnd for sample in new_snd: snd_index = sound.get_index(sample) factor = 0 snd_samp = sound.get_sample(snd, snd_index) if snd_index <= fade_length: left = (sound.get_left(snd_s

def淡入snd,淡入长度: “为该波形文件进行声音淡入” new_snd=sound.copysnd

for sample in new_snd:
    snd_index = sound.get_index(sample)
    factor = 0
    snd_samp = sound.get_sample(snd, snd_index)
    if snd_index <= fade_length:
        left = (sound.get_left(snd_samp) * factor)
        right = (sound.get_right(snd_samp) * factor)
        factor += 0.25
        sound.set_values(sample,int(left),int(right))
    else:
        left = sound.get_left(sample)
        right = sound.get_right(sample)
        sound.set_values(sample, int(left), int(right))

return new_snd
当您在for循环中每次运行时都将factor设置为零时,left和right将始终为零。必须在for循环之外声明因子:

def fade_in (snd, fade_length):
    new_snd = sound.copy(snd)
    factor = 0

    for sample in new_snd:
        snd_index = sound.get_index(sample)
        snd_samp = sound.get_sample(snd, snd_index)
        if snd_index <= fade_length:
            left = (sound.get_left(snd_samp) * factor)
            right = (sound.get_right(snd_samp) * factor)
            factor += 0.25
            sound.set_values(sample,int(left),int(right))
        else:
            left = sound.get_left(sample)
            right = sound.get_right(sample)
            sound.set_values(sample, int(left), int(right))

    return new_snd

那只是一段代码。你必须问一个问题。我试图用python编写一个代码来实现声音淡入,但这段代码不起作用。在如果snd_指数的部分,哦,实际上我知道了,但是现在我有一个新问题,当snd_指数