python首尾拼接wav
发布日期:2022/10/17 20:27:12 浏览量:
pydub是一个可以对音频进行一些基本处理的python模块,首先pip install pydub下载该模块,然后对两个wav进行首尾拼接:
def combine(wav1_path,wav2_path,out_path):
’’’
param wav1_path: 第一个wav的路径
param wav2_path: 第二个wav的路径
param out_path: 拼接后的wav路径
’’’
wav1=AudioSegment.from_wav(wav1_path)
wav2 = AudioSegment.from_wav(wav2_path)
playlist=wav1+wav2
playlist.export(out_path,format=’wav’)
wav1_path=’1.wav’
wav2_path=’2.wav’
out_path=’out.wav’
combine(wav1_path,wav2_path,out_path)
def wav_comb(*args):
n=args[0][0] # 需要拼接的wav个数
i=1
sounds=[]
while (i<=n):
sounds.append(AudioSegment.from_wav(args[0][i]))
i+=1
playlist = AudioSegment.empty()
for sound in sounds:
playlist += sound
playlist.export(args[0][n+1], format="wav")
wav1_path=’1.wav’
wav2_path=’2.wav’
wav3_path=’3.wav’
wav4_path=’4.wav’
out_path=’out.wav’
list=[4,wav1_path,wav2_path,wav3_path,wav4_path,out_path]
wav_combine(list)
马上咨询: 如果您有业务方面的问题或者需求,欢迎您咨询!我们带来的不仅仅是技术,还有行业经验积累。
QQ: 39764417/308460098 Phone: 13 9800 1 9844 / 135 6887 9550 联系人:石先生/雷先生