【发布时间】:2020-01-26 04:14:26
【问题描述】:
我正在尝试从多个 wav 文件中创建一个音频文件。使用 tkinter 和 pygame.mixer,我已将按键转换为存储音频样本及其调用时间的字典。 {sound1:10000, sound2:10001, ect...}
到目前为止,我已经设计了一种添加静音块的方法:
def change_speed(seconds):
'''modifies the metronome beat to loop at different speeds. This is done by creating a new wav file.'''
#original wav file is 0.1 seconds long, so subtract that from time added
seconds-=0.1
#read the original wav file
original = scipy.io.wavfile.read('Downloads\\sounds\\metronome_original.wav')
#use sample rate of the original file (should be 44100) to create a new block of silence
add_secs = np.array([[0]]*round(original[0]*seconds))
add_secs.dtype='int16'
#concatenate new block to original
new = np.concatenate((original[1], add_secs))
scipy.io.wavfile.write('Downloads\\sounds\\metronome.wav', original[0], new)
有没有办法将重叠的数组(如 [[0,0,1,1,2,0], [0,0,0,3,2,1]])合并到一个单独的 wav 文件中?
更新: 更具体地说,我试图合并两个播放时间重叠的音频样本,就像一个 DJ 在另一首歌曲完成之前开始播放一首歌曲。有没有办法用python中生成的整数或字节数组来做到这一点? 像这样:
【问题讨论】:
-
This answer 关于交叉淡入淡出的音频可能很有用。
标签: python python-3.x numpy pygame wav