Skip to content

Instantly share code, notes, and snippets.

@chinalwb
Created March 14, 2024 08:57
Show Gist options
  • Save chinalwb/846b5c007c6fc09719fd50ea609ff336 to your computer and use it in GitHub Desktop.
Save chinalwb/846b5c007c6fc09719fd50ea609ff336 to your computer and use it in GitHub Desktop.
Add silence to wav file with Python
# Prerequisite:
# Install ffmpeg / ffplay from https://evermeet.cx/ffplay/
from pydub import AudioSegment
from pydub.playback import play
audio_in_file = "in_sine.wav"
audio_out_file = "out_sine.wav"
# create 1 sec of silence audio segment
one_sec_segment = AudioSegment.silent(duration=1000) #duration in milliseconds
#read wav file to an audio segment
song = AudioSegment.from_wav(audio_in_file)
#Add above two audio segments
final_song = one_sec_segment + song
#Either save modified audio
final_song.export(audio_out_file, format="wav")
#Or Play modified audio
play(final_song)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment