当一个较长的.wav文件继续播放时,如何使一个较短的.wav文件循环一遍又一遍?

2024-09-29 19:21:06 发布

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

这是为了上课。教授要求我们合并两个不同长度的wav文件,如果前景文件比背景长,我们被要求让背景继续循环,而前景wav文件继续播放。我已经设法把他们结合起来,但我所有的尝试创造一个循环的背景继续发挥是徒劳的。也不允许使用模块。你知道吗

def main():
  #open and make fg "foreground" sound
  openFileName = pickAFile()
  fgsound = makeSound (openFileName)

  #open and make bg "background" sound
  openFileName2 = pickAFile()
  bgsound = makeSound (openFileName2)

  finalsound = combineSounds (fgsound, bgsound)

  explore (finalsound)


def combineSounds(fgsound, bgsound):
  sampleList1 = getSamples(fgsound)
  sampleList2 = getSamples (bgsound)

  fglength = getLength (fgsound)
  bglength = getLength (bgsound)



  for i in range(fglength):

    amp1 = getSampleValue (sampleList1[i])
    amp2 = getSampleValue (sampleList2[i])
    amp2 = ((amp2)/3)

    if amp2 > bglength:
      amp2 = (bglength * i) - amp2 

    amp3 = amp1 + amp2

    if (amp3 > 32767):
      amp3 = 32767
    elif (amp3 < -32768):
      amp3 = -32768


    setSampleValue (sampleList1[i], amp3)

Tags: and文件makedefopen背景wav前景

热门问题