用Python(pydub)创建空的音频段文件

用Python(pydub)创建空的音频段文件,python,python-3.x,pydub,audiosegment,Python,Python 3.x,Pydub,Audiosegment,我是初学者。我正在尝试循环浏览mp3文件的路径列表,并合并所有mp3: combined_sounds = AudioSegment.from_mp3('./00.mp3') for file in files: sound = AudioSegment.from_mp3(file) combined_sounds= combined_sounds + sound; # .... 在浏览列表之前,我需要定义组合的_音,但在浏览循环之前,我不想在其中添加任何内容。现在我的小技巧是使用

我是初学者。我正在尝试循环浏览mp3文件的路径列表,并合并所有mp3:

combined_sounds = AudioSegment.from_mp3('./00.mp3')

for file in files:
  sound = AudioSegment.from_mp3(file)
  combined_sounds= combined_sounds + sound;

# ....
在浏览列表之前,我需要定义组合的_音,但在浏览循环之前,我不想在其中添加任何内容。现在我的小技巧是使用一个空的mp3文件00.mp3,但这不是最好的解决方案。我将如何做到这一点

我尝试了combined_sounds=和combined_sounds=无,但当我进入循环并尝试将其转换为音频段时,两者都会给我带来错误。我可以在循环之前创建一个空的AudioSegment吗?

您可以使用AudioSegment中的empty函数创建一个空段:

combined_sounds = AudioSegment.empty()

for file in files:
   sound = AudioSegment.from_mp3(file)
   combined_sounds += sound

是否要在开始时添加一些静音?不,我只想合并列表中的所有文件。开始时的00.mp3不是沉默,只是因为我不知道如何正确声明变量,所以它只是一种解决方法: