参数值不正确(类型正确)。在JES中(Python/Jython)

2024-10-01 15:45:35 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,所以我正在用JES为Python类编写一些编码作业。我们的任务是拍摄一个声音,在背景中加入一些白噪音,同时还要添加一个回声。有一点更严格,但我相信我可以接受。我们有四个不同的函数:一个主函数,一个基于用户定义的时间长度和回声量的回声方程,一个白噪声生成函数,以及一个合并噪声的函数。在

这是我到目前为止,还没有开始合并或主要。在

#put the following line at the top of your file. This will let
#you access the random module functions
import random

#White noise Generation functiton, requires a sound to match sound length
def whiteNoiseGenerator(baseSound) :
 noise = makeEmptySound(getLength(baseSound))
 index = 0  
 for index in range(0, getLength(baseSound)) :
  sample = random.randint(-500, 500)
  setSampleValueAt(noise, index, sample)
 return noise


def multipleEchoesGenerator(sound, delay, number) :
  endSound = getLength(sound)
  newEndSound = endSound +(delay * number)

  len = 1 + int(newEndSound/getSamplingRate(sound))
  newSound = makeEmptySound(len)

  echoAmplitude = 1.0
  for echoCount in range (1, number) :
    echoAmplitude = echoAmplitude * 0.60
    for posns1 in range (0, endSound):
    posns2 = posns1 + (delay * echoCount)
    values1 = getSampleValueAt(sound, posns1) * echoAmplitude
    values2 = getSampleValueAt(newSound, posns2)
    setSampleValueAt (newSound, posns2, values1 + values2)
return newSound

每当我试图加载它时都会收到这个错误。在

错误是:

^{pr2}$

这一行代码是:

setSampleValueAt (newSound, posns2, values1 + values2)

有人知道这里会发生什么吗?任何帮助都将是伟大的,因为我希望给自己足够的时间来完成这项任务的编码。我以前也遇到过类似的错误,它通常是一个语法错误,但是我在这里没有看到任何这样的错误。在

这个声音是在我运行这个程序之前发出的,我将delay和number分别定义为1和3。在


Tags: the函数numberforindex错误randomdelay
1条回答
网友
1楼 · 发布于 2024-10-01 15:45:35

检查setSampleValueAt的参数;示例值必须超出界限(应该在-32768-32767之内)。你需要为你的算法做一些输出钳制。在

另一种可能性(根据进一步的输入,这确实是错误)是您的回声将超出样本的范围-也就是说,如果您的样本长度为5秒,而回波长度为0.5秒;或者posns1 + delay超出了样本的长度;新声音的长度计算不正确。在

相关问题 更多 >

    热门问题