我想在某些时间在背景音乐和说明的情况下生成带有锻炼的mp3文件(例如,“更努力”,“再重复一次!”)
我用pico2wave生成指令,并用pydub组装它们。
我这样做:
for timing,phrase in phrases.items():
fileToAdd = pydub.AudioSegment.from_file(rep+"/"+str(timing)+".wav")
finalFile = finalFile.fade(to_gain=-35, start=(timing*1000)-500, duration=500) # on diminue la chanson, une demi seconde avant
finalFile = finalFile.fade(to_gain=+35, start=(timing*1000)+len(fileToAdd), duration=500)
fichierFinal = fichierFinal.overlay(fileToAdd,position=timing*1000)
结果文件的质量非常差。我尝试消除“淡入淡出效果”,并且质量很好(但听不太清楚“说明”)
我该如何更改?我可以轻松进行淡入淡出效果吗?
谢谢,
问候,
阿克塞尔
最佳答案
我认为问题在于您先使音频衰减,然后又对其进行增强(因此,每次衰减然后增强时,您将损失35dB的动态范围)。
我认为更好的解决方案是拆分音频,仅减少所需的部分(不进行任何增强操作)。
您在此处执行的操作有时称为“ducking”,因此我将在下面使用该名称:
def duck(sound, position, duration, gain=-15.0, fade_duration=500):
"""
sound - an AudioSegment object
position - how many milliseconds into the sound the duck should
begin (this is where overlaid audio could begin, the fade down
will happen before this point)
duration - how long should the sound stay quiet (milliseconds)
gain - how much quieter should the sound get (in dB)
fade_duration - how long sound the fades last (in milliseconds)
"""
# this part is from the beginning until the end of the ducked section
first_part = sound[:position+duration]
first_part = first_part.fade(to_gain=gain, end=position, duration=fade_duration)
# this part begins where the fade_up happens (will just fade in)
second_part = sound[position+duration:]
second_part = second_part.fade(from_gain=gain, start=0, duration=fade_duration)
return first_part + second_part
for timing, phrase in phrases.items():
fileToAdd = pydub.AudioSegment.from_file(rep+"/"+str(timing)+".wav")
finalFile = duck(finalFile, position=timing*1000, duration=len(fileToAdd))
finalFile = finalFile.overlay(fileToAdd, position=timing*1000)
经过一些测试,35dB可能超出您的期望。 15dB听起来对我的耳朵非常好:)