python - 声音回声函数Python

标签 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 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]*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

关于python - 声音回声函数Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32887906/

相关文章:

c - 从 Beep() 中删除 sleep ,这是产生声音的替代方法?

python - 如何对 SciPy 曲线拟合施加约束?

Python/Matplotlib - 表示平均值的颜色条

javascript:在另一个函数中获取函数变量的值

python - 将 +1 添加到函数内的变量

javascript - setInterval 给我 TypeError : Cannot call method 'apply' of undefined

python - 音频文件到文本文件python

python - 有没有办法迭代多个数据帧,将它们写入带有格式的多个 Excel 工作表?

audio - gstreamer管道混合了三个音频源?

vb.net - 在 vb 中播放音频时出现 AccessViolationException