繁体   English   中英

在 Python (pydub) 中创建一个空的 AudioSegment 文件

[英]Creating an empty AudioSegment File in Python (pydub)

初学者在这里。 我正在尝试遍历 mp3 文件的路径列表并合并所有 mp3:

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

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

# ....

我需要在遍历列表之前定义combined_sounds - 但我不想在遍历循环之前将任何内容放入其中。 现在我的小技巧是使用一个空的 mp3 文件00.mp3 ,但这不是最好的解决方案。 我将如何做到这一点?

我尝试了 combine_sounds combined_sounds = ''combined_sounds = None但当我进入循环并尝试将其转换为 AudioSegment 时,两者都让我出错。 我可以在循环之前创建一个空的 AudioSegment 吗?

您可以使用 AudioSegment 中的empty() function 创建一个空白段:

combined_sounds = AudioSegment.empty()

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM