Currently I am using this code to cut the audio file into small chunks:
sound = AudioSegment.from_mp3("1.WAV")
f=open("decoded.txt", "a+")
chunks = split_on_silence(sound,min_silence_len=280,silence_thresh=-33,keep_silence=150)
for i, chunk in enumerate(chunks):
print(i)
print("\n")
chunk.export(folder+"/chunk{0}.wav".format(i), format="wav")
AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), folder+"/chunk{0}.wav".format(i))
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
print("Listening...")
audio = r.record(source) # read the entire audio file
f.write((r.recognize_google(audio) +" "))
f.close();
This creates chunks of files split according to silence... But what i want is that whenever an audio is split, the next slice starts from 2 seconds back so that any word which might be cut may come. Something like if silences are at time 10,13,18,22 then my slices should be 0-10,8-13,11-18,16-22. I am using pydub for splitting according to silence. Can i change something in pydub or is there some other package which does this work?