Python 声音回声函数

Python 声音回声函数,python,function,audio,echo,delay,Python,Function,Audio,Echo,Delay,我需要写一个函数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 t

我需要写一个函数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
以及:

谁能帮帮我,因为我搞不懂

    samps2 = [0]*int(samps1*time_delay) + samps1
TypeError: can't multiply sequence by non-int of type 'float'
您的线路:

[0]*float(samps1*time_delay) + samps1
尝试将序列
[0]
乘以
浮点数
。这会导致错误
TypeError:不能将序列与“float”类型的非整数相乘

您可以改为强制转换为int:

[0]*int(len(samps1)*time_delay) + samps1

问题/问题是什么?samps2=[0]*float(samps1*time_delay)+samps1 TypeError:不能将序列乘以'float'类型的非整数。请编辑您的问题,并指定该行(292)在示例中的位置。samps2=[0]*int(samps1*time_delay)+samps1 TypeError:无法将序列与“float”类型的非整数相乘使用int
samps1
时的相同问题也是一个序列。。。和时间延迟
a float。。。使用
samps1*int(time\u delay)
samps2=[0]*samps1*int(time\u delay)+samps1 TypeError:不能将序列与'list'类型的非int相乘
[0]*int(len(samps1)*time\u delay)+samps1
是我认为您正在尝试实现的目标。
[0]*int(len(samps1)*time_delay) + samps1