使用python的pydub首尾拼接wav
发布日期:2022/10/7 11:32:01 浏览量:
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)
多个wav的拼接:
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)
————————————————
版权声明:本文为CSDN博主「youroldz」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_37601846/article/details/103503695
业务实施流程
马上咨询: 如果您有业务方面的问题或者需求,欢迎您咨询!我们带来的不仅仅是技术,还有行业经验积累。
QQ: 39764417/308460098 Phone: 13 9800 1 9844 / 135 6887 9550 联系人:石先生/雷先生