所以我写了一个代码来创建两个声音文件,提供一些细节并探索它们,但是我很难用一部分来创建第三个声音文件,它的长度是前两个声音文件中较长的一个,并且采样率两者(他们有相同的sr)。该函数旨在获取前两个声音文件的所有索引的样本值,将它们相加,然后将它们复制到第三个声音文件中。我以为我有它,但是当我浏览第三个文件时,它出现了空白。
def sound():
a = pickAFile()
b = pickAFile()
sound1 = makeSound(a)
sound2 = makeSound(b)
sr1 = getSamplingRate(sound1)
sr2 = getSamplingRate(sound2)
printNow(sr1)
printNow(sr2)
play(sound1)
play(sound2)
explore(sound1)
explore(sound2)
if sr1 == sr2:
printNow('Sampling Rate 1: %d \nSampling Rate 2: %d' % (sr1, sr2))
else:
printNow('Sampling Rates are not equal.')
c=getLength(sound1)
d=getLength(sound2)
printNow('sound1: %d, sound2: %d' % (c, d))
sound3 = Sound(getLength(sound2), int(sr1))
for index in range(0, getLength(sound1)):
value = getSampleValueAt(sound1, index)
for index in range(0, getLength(sound2)):
value2 = getSampleValueAt(sound2, index)
for index in range(0, getLength(sound3)):
setSampleValueAt(sound3, index, value+value2)
play(sound3)
explore(sound3)