我的目录中有大约 245 个 .webm 文件。我想将所有这 245 个文件合并到一个名为 output.webm 的文件中。我正在使用 python 的“moviepy”模块来实现这一点。这是我到目前为止所做的:import osfrom moviepy.editor import *audio_folder='path/to/directory'audio_files = [audio_folder+'/'+img for img in os.listdir(audio_folder) if img.endswith(".webm")]print(audio_files)audio = concatenate_audioclips(audio_files)audio.write_audiofile('output.webm')执行此操作时出现以下错误:Traceback (most recent call last):File "demo.py", line 17, in <module> audio = concatenate_audioclips(audio_files)File "C:\Users\abc\AppData\Local\Programs\Python\Python38-32\lib\site- packages\moviepy\audio\AudioClip.py", line 315, in concatenate_audioclipsdurations = [c.duration for c in clips]File "C:\Users\abc\AppData\Local\Programs\Python\Python38-32\lib\site- packages\moviepy\audio\AudioClip.py", line 315, in <listcomp> durations = [c.duration for c in clips]AttributeError: 'str' object has no attribute 'duration'我哪里错了?
1 回答
千巷猫影
TA贡献1829条经验 获得超7个赞
我将字符串列表传递给concatenate_audioclips 函数而不是list of AudioClip Objects. 这就是我为解决问题所做的。
audio_folder='path/to/directory'
audio_files = [audio_folder+'/'+img for img in os.listdir(audio_folder) if img.endswith(".webm")]
print(audio_files)
audios = []
for audio in audio_files :
audios.append(AudioFileClip(audio))
audioClips = concatenate_audioclips([audio for audio in audios])
audioClips.write_audiofile('output.webm')
添加回答
举报
0/150
提交
取消