有没有办法批量标准化音频文件的文件夹?

Is there a way to batch normalize a folder of audio files?

我有一个包含 2000 多个音频文件的文件夹,所有这些文件都被标准化到相同的水平(特别是 -14 dB)。有没有我可以在 Python 或 C# 中 write/use 的脚本,这样我就不必单独编辑每个脚本了?

您可以使用pydub模块以最少的代码实现峰值音量归一化。安装 pydub 使用

pip install pydub

使用os.walk可以得到文件名;通过使用 endswith 你可以检查文件格式。

此代码规范化 BASE_PATH 中的所有音频文件并将它们保存在 OUTPUT_PATH 中。

你得根据自己的情况改BASE_PATHOUTPUT_PATHAUDIO_FORMAT_LIST

from pydub import AudioSegment
import os

BASE_PATH = "your/files/folder/path/"
OUTPUT_PATH = "path/that/you/want/save/new/files/"
AUDIO_FORMAT_LIST = ["mp3", "wav"]  # audio formats you want to change


def match_target_amplitude(sound, target_dBFS):
    change_in_dBFS = target_dBFS - sound.dBFS
    return sound.apply_gain(change_in_dBFS)


filenames = next(
    os.walk(BASE_PATH),
    (None, None, []),
)
for filename in filenames:
    flag = False
    file_audio_format = ""
    for audio_format in AUDIO_FORMAT_LIST:
        if filename.endswith("." + audio_format):
            flag = True
            file_audio_format = audio_format
            break
    if flag:
        sound = AudioSegment.from_file(BASE_PATH + filename, file_audio_format)
        normalized_sound = match_target_amplitude(sound, -14.0)
        normalized_sound.export(
            OUTPUT_PATH + "nomrmalized" + filename, format=file_audio_format
        )