2022-09-14

Using a for loop to rename processed .wav file with pydub AudioSegment function

I am trying to rename multiple files in a loop using the AudioSegment function. Below is the function for a single file (which works perfectly

from pydub import AudioSegment
audio = AudioSegment.from_wav("./OM1/BMM.wav")

new_audio = audio[1000:len(audio)-1000] 
new_audio.export('newSong.wav', format="wav")

Now I want to loop through the whole folder but it seems to give me just one folder

i = 1
for wave_file in glob.glob("./OM1/*.wav"):   #Folder containing subject files 
    sound = AudioSegment.from_wav(wave_file)
    new_sound = sound[1000:len(audio)-1000] 
    new_sound.export('newSong.wav', format="wav")


No comments:

Post a Comment