python - 使用 pydub 进行多次淡入淡出效果后质量很差

标签 python audio mp3 wav pydub

我想生成锻炼 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 的动态范围)。

我认为更好的解决方案是分割音频并仅减少您需要的部分(不进行任何增强操作)。

您在这里执行的操作有时称为“闪避”,因此我将在下面使用该名称:

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 对我来说听起来不错:)

关于python - 使用 pydub 进行多次淡入淡出效果后质量很差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33880261/

相关文章:

python - numpy中二维的跨步卷积

python - 使用 bool 数组掩码,将 False 值替换为 NaN

javascript - 在 URL 处内嵌播放声音文件

Android Mp3 从 url 播放

apache-flex - 如何在mouseEvent情况下仅触发一次函数

JavaFX MediaPlayer - 音乐在 10 秒后停止

Python Anywhere - 没有名为 'sklearn.linear_model._stochastic_gradient' 的模块

python - 河内代表塔

audio - android;嘶嘶声

python - 如何使用 pyglet 播放流式音频?