如何使用“exec”使用 pydub 覆盖而不创建“none”文件类型?
我正在尝试使用 pydub 组合多个音频文件。
当我创建一个字符串,然后尝试exec
,同时将其分配给变量时 当我尝试导出音频时,它不起作用,并且变量返回“无”类型错误。
from pydub import AudioSegment
bass = AudioSegment.from_file("bass.ogg")
gtr = AudioSegment.from_file("guitar.ogg")
tracks = "gtr.overlay(bass)"
execTracks = exec(tracks) # I'd like this to work
manualTracks = gtr.overlay(bass) # This works properly
print(execTracks)
print(manualTracks)
output:
None
<pydub.audio_segment.AudioSegment object at 0x100b915e0>
我想使用“exec”的原因是因为“tracks”变量将根据可用文件而变化。
感谢您的任何提示或指导!
I'm trying to use pydub to combine multiple audio files.
When I create a string and then try to exec
that while assigning it to a variable
it doesn't work and the variable returns a 'none' type error when I try to export the audio.
from pydub import AudioSegment
bass = AudioSegment.from_file("bass.ogg")
gtr = AudioSegment.from_file("guitar.ogg")
tracks = "gtr.overlay(bass)"
execTracks = exec(tracks) # I'd like this to work
manualTracks = gtr.overlay(bass) # This works properly
print(execTracks)
print(manualTracks)
output:
None
<pydub.audio_segment.AudioSegment object at 0x100b915e0>
The reason I want to use 'exec' is because the 'tracks' variable will change depending on the files available.
Thank you for any tips or guidance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论