gpt4 book ai didi

python - 从计算机读取多个 .wav 文件并将它们合并到 numpy 数组

转载 作者:太空宇宙 更新时间:2023-11-04 04:34:20 24 4
gpt4 key购买 nike

我需要将多个 wav 文件读取到单独的 numpy 数组中,然后将这些 numpy 数组合并为一个并将其保存为 wav 文件。

我该怎么做?

最佳答案

解决方法:

from scipy.io.wavfile import read, write
import numpy as np

fs, x = read('test1.wav')
f2, y = read('test2.wav')

#z = x + y # this is to "mix" the 2 sounds, probably not what you want
z = np.concatenate((x, y)) # this will add the sounds one after another

write('out.wav', fs, z)

当执行 x + y 时,如果 2 个数组的长度不同,您需要对最短的数组进行零填充,以便它们在求和之前最终具有相同的长度。

关于python - 从计算机读取多个 .wav 文件并将它们合并到 numpy 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52073649/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com