pip install SpeechRecognition
After installing the package we need to copy and paste following code an run our program
import speech_recognition as sr
# importing pachage
r=sr.Recognizer()
print(sr.Microphone.list_microphone_names())
# checking for microphone
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source,duration=1)
# r.energy_threshold()
print("say anything : ")
audio= r.listen(source)
try:
text = r.recognize_google(audio)
print(text)
except:
print("sorry, could not recognise")