You are getting this error because you are not not instantiating the microphone in a context manager.
To put it simply a context manager simply means a 'with' statement or a statement that begins with the with keyword. It helps in wrapping a piece of code helps in performing some tasks before and after it, like freeing up some resource.
You can do it like this:
with speech_recognition.Microphone() as microphone:
In case you wish to learn more about python use this video: