Created
March 14, 2024 08:57
-
-
Save chinalwb/846b5c007c6fc09719fd50ea609ff336 to your computer and use it in GitHub Desktop.
Add silence to wav file with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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