我需要写一个函数echo,它接受一个文件名和一个浮点值time_delay,它表示一个秒数。然后,echo应该处理声音,原始声音被一个副本覆盖它本身已经被time_delay向前移动了。
这是我到目前为止所做的:
def add_scale_2(L, M, L_scale, M_scale):
""" add_scale_2 has as intput list L and list M and rertuns a new list LC,
with a linear sum of the two lists times their scale respectively. LC will use the length of the
shortest list
"""
if len(L) >= len (M):
N = len(M)
else:
N = len(L)
LC = [L[i]*L_scale + M[i]*M_scale for i in range(N)]
return LC
和
def echo(filename, time_delay):
print "Playing filename1 ..."
play(filename)
print "Reading in the sound data..."
samps1, sr = readwav(filename)
samps2 = [0]*float(samps1*time_delay) + samps1
print "Computing new sound..."
newsamps = add_scale_2(samps1, samps2, 0.5, 0.5)
newsr = sr # no change to the sr
writewav( newsamps, newsr, "out.wav" )
print "Playing new sound..."
play( 'out.wav' )
有人可以帮助我,因为我无法解决这个问题!
samps2 = [0]*int(samps1*time_delay) + samps1
TypeError: can't multiply sequence by non-int of type 'float'
答案 0 :(得分:1)
你的专栏:
[0]*float(samps1*time_delay) + samps1
尝试将序列[0]
乘以float
。哪会导致错误TypeError: can't multiply sequence by non-int of type 'float'
您可以转换为int:
[0]*int(len(samps1)*time_delay) + samps1