如何用静音填充多个音频 wav 文件

How to pad multiple audio wav files with silence

我正在尝试填充音频 wav 文件。我找到了下面的代码。我能否获得任何帮助以将其应用于具有不同名称的多个文件?

from pydub import AudioSegment

pad_ms = 1000
audio = AudioSegment.from_wav('sit.wav')
assert pad_ms > len(audio), + str(full_path)
silence = AudioSegment.silent(duration=pad_ms-len(audio)+1)

padded = audio + silence
padded.export('sit_1*.wav', format='wav')

如何遍历文件夹中的文件:

from pydub import AudioSegment
import os # Needed for os.listdir

pad_ms = 1000

path = "/the/path/name"

for filename in os.listdir(path): # Loop over all items in the path
    if (filename.endswith(".wav")): # Check if the file ends with .wav
        audio = AudioSegment.from_wav(filename)
        assert pad_ms > len(audio), + str(full_path)
        silence = AudioSegment.silent(duration=pad_ms-len(audio)+1)

        padded = audio + silence

        newFilename = filename.split(".")[0] + "_1.wav" # And something like this for the new name
        padded.export(newFilename, format='wav')