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:
import speech_recognition
recognizer=speech_recognition.Recognizer()
with speech_recognition.Microphone() as microphone:
print('Yes')
audio=recognizer.listen(microphone)
try:
text=recognizer.recognize_google(language='it')
print('Text: '+text)
except speech_recognition.UnknownValueError:
print('Unknown Value')
except speech_recognition.RequestError:
print('Invalid Request')
In case you wish to learn more about python use this video: