0

I have a series of wav files I would like to combine and export as a single wav using Pydub. I would like the audio from the original files to play back at different times in the exported file e.g. the audio in audio_1.wav starts at time=0 in the exported file while the audio in audio_2.wav starts at time=5 instead of both starting at time=0 as the overlay function has them. Is there any way to do this? Below is the code I currently have for importing, overlaying, and exporting the audio files.

from pydub import AudioSegment

audio_1 = AudioSegment.from_file("audio_1.wav",
                               format="wav")

audio_2 = AudioSegment.from_file("audio_2.wav",
                               format="wav")

overlay = vln_audio_1.overlay(vla_audio_2)
file_handle = overlay.export("output2.wav", format="wav")
John
  • 40
  • 4
  • did you check what you have in files - maybe second file has 5 seconds of silences at start and this is all problem. – furas Nov 04 '21 at 14:00
  • No, that's what I want. Currently all files start at the same time with no silence. – John Nov 04 '21 at 16:55
  • maybe you should first add some silence at the beginning. `silence = AudioSegment.silent(duration=5000)` and `audio_2 = silence + audio_2` – furas Nov 04 '21 at 17:24
  • based on [documentation](https://github.com/jiaaro/pydub/blob/master/API.markdown#audiosegmentoverlay) it may need `overlay(..., position=5000)` – furas Nov 04 '21 at 17:25

1 Answers1

0

I didn't test it but based on documentation it may need overlay(..., position=5000)


BTW:

you may also add silence at the beginning to move audio

silence_5_seconds = AudioSegment.silent(duration=5000)

audio_2 = silence_5_seconds + audio_2
furas
  • 134,197
  • 12
  • 106
  • 148