Ryan
Ryan

Reputation: 1

How can I overlay ALL of the wav files in a folder to make one new wav file in python?

from pydub import AudioSegment 

I am using pydub Audiosegment but can only overlay 2 wav files. I would like to overlay All the wav files in a directory without using their filenames.

from pydub import AudioSegment
from glob import glob 
import pandas as pd 

sound1 = AudioSegment.from_file("/Users/ryan/Code/PERSONAL_PROJ/combine_wav/85BPM/sound1.wav", format="wav")

sound2 = AudioSegment.from_file("/Users/ryan/Code/PERSONAL_PROJ/combine_wav/85BPM/sound2.wav", format="wav")

overlay = sound1.overlay(sound2, position=0)
file_handle = overlay.export("/Users/ryan/Code/PERSONAL_PROJ/combine_wav/sound_build_up/soundA.wav", format="wav")
sound3 = AudioSegment.from_file("/Users/ryan/Code/PERSONAL_PROJ/combine_wav/85BPM/sound3.wav", format="wav")
soundA = AudioSegment.from_file("/Users/ryan/Code/PERSONAL_PROJ/combine_wav/sound_build_up/soundA.wav", format="wav")
overlay = soundA.overlay(sound3, position=0)
file_handle = overlay.export("/Users/ryan/Code/PERSONAL_PROJ/combine_wav/final_sound/85_bpm/test.wav", format="wav")

Upvotes: 0

Views: 189

Answers (0)

Related Questions