Adding Silent Frame To Wav File Using Python
First time posting here, lets see how this goes. I trying to write a script in python which would add a second of silence in the beginning of the wav file, but so far been unsucces
Solution 1:
There are libraries that can do these kind of audio manipulation easily with least amount of code. One such is pydub.
You can install pydub
as below and detail about dependencies are herepip install pydub
Using pydub
, you can read different audio formats (wav
in this case), convert them to audio-segment and then perform manipulations or simply play it.
You can also create an silent audio-segment of set period and add two segment with '+' operator.
Source Code
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)
Post a Comment for "Adding Silent Frame To Wav File Using Python"