【发布时间】:2019-08-30 23:44:14
【问题描述】:
我使用 python 3.7、numpy 和 scipy 制作了一个程序,它使用 pi 的数字生成波形,并将它们拼接在一起以制作一首“歌曲”。我唯一的问题是每个音符之间都有间隙。
我尝试过使用数学函数使每个音符的波浪逐渐消失,我尝试让音符重叠一点(运气不好),还有一些没有做任何事情的疯狂事情...
import numpy as np
from scipy.io.wavfile import write
pi = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848"
piarray = list(pi)
piarray.remove(".")
print(piarray)
# Samples per second
sps = 44100
# Frequency / pitch of the sine wave
freq_hz = 440.0
# Duration
duration_s = 0.2
each_sample_number = np.arange(duration_s * sps)
for i in range(len(piarray)):
if(piarray[i] == "0"):
freq_hz = 277.18
elif(piarray[i] == "1"):
freq_hz = 311.13
elif(piarray[i] == "2"):
freq_hz = 369.99
elif(piarray[i] == "3"):
freq_hz = 415.30
elif(piarray[i] == "4"):
freq_hz = 466.16
elif(piarray[i] == "5"):
freq_hz = 554.37
elif(piarray[i] == "6"):
freq_hz = 622.25
elif(piarray[i] == "7"):
freq_hz = 739.99
elif(piarray[i] == "8"):
freq_hz = 830.61
else:
freq_hz = 932.33
waveform = np.sin(2 * np.pi * each_sample_number * freq_hz / sps)*0.3
#The line above and below this one make an individual note.
waveform_integers = np.int16(waveform * 32767)
if(i == 0):
waveformc = waveform_integers
print(waveformc)
else:
waveformc = np.append(waveformc, waveform_integers, axis=None)
write('song.wav', sps, waveformc)
print("DONE")
我已尝试寻找此特定问题的解决方案,但在任何地方都没有找到任何相关内容。我只是希望波形文件在每个音符之间没有间隙,但是有。感谢您能给我的任何帮助!
【问题讨论】:
标签: python numpy audio scipy wave