I have tried it on python shell 3.5.8

import speech_recognition as sr
import webbrowser as wb

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe 

# obtain audio from the microphone  
r = sr.Recognizer()  
with sr.Microphone() as source:  
   print("Please wait. Calibrating microphone...")  
   # listen for 5 seconds and create the ambient noise energy level  
   r.adjust_for_ambient_noise(source, duration=5)  
   print("Say something!")  
   audio = r.listen(source)  

# recognize speech 
    text = r.recognize_google(audio)
    print("I thinks you said '" + r.recognize_google(audio) + "'")

    f_text='https://www.google.co.in/search?q=' + text
#except sr.UnknownValueError:  
#  print("I could not understand audio")  
except sr.RequestError as e:  
   print("error; {0}".format(e))

except Exception as e:
   print (e)
File "C:\Users\manoj\AppData\Local\Programs\Python\Python35\lib\site- 
packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or 
len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()

0 Answers