Python中的淡出声音
这是我的Python中的淡出声音,python,audio,Python,Audio,这是我的淡出功能 def fade_out (snd, fade_length): new_snd = sound.copy(snd) factor = 1.0/fade_length fade_o = 1 for sample in new_snd: sound.set_left(sample, int(sound.get_left(sample)*fade_o)) sound.set_right(sample, int(soun
淡出功能
def fade_out (snd, fade_length):
new_snd = sound.copy(snd)
factor = 1.0/fade_length
fade_o = 1
for sample in new_snd:
sound.set_left(sample, int(sound.get_left(sample)*fade_o))
sound.set_right(sample, int(sound.get_right(sample)*fade_o))
if fade_o > 0:
fade_o = fade_o - factor
return new_snd
我遇到的第一个问题是这部分:
if fade_o > 0:
fade_o = fade_o - factor
我不明白为什么只从一次中减去face\o
。我以为fade\u o
将继续从中减去,直到它达到0
第二个问题是我不知道如何在我想要的时间开始淡出。例如,如果声音长度为600000,衰减长度为100000,我希望以500000的偏移量开始衰减(即600000-100000
)。我不知道该怎么做
我想到了以下几点:
for sample in new_snd:
if sound.get_index(sample) > (len(snd)-fade_length):
sound.set_left(sample,........)
但是,这似乎不起作用。您使用的是什么音库?是的,它来自PyGraphics