r = sr.Recognizer()
with sr.Microphone() as source:
    audio = r.listen(source)
try:
    print('You said ' + r.recognize(audio))
except LookupError:
    pass
How to embed Google Speech to Text API in Python program?