def fade_in(和,渐变长度): '''为那个wav文件做一个声音淡入'''new snd = sound.copy(snd)
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
答案 0 :(得分:0)
left
和right
将始终为零,因为您在for循环中每次运行时将factor
设置为零。您必须在for循环之外声明factor
:
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