I am using following code for simple speech recognition. This code detects spoken phrase if there is silence and r.adjust_for_ambient_noise(source, duration=1)
r.adjust_for_ambient_noise(source, duration=1)