Speech Recognition

Hi,
I am trying to write a speech recognition code in psychopy but I am getting the following error
File “C:\Users\hp\Desktop\psychopy_exp\SpeechRecog.py”, line 11, in
str=r.recognize_google(audio).encode(‘utf-8’).script()
File “C:\Users\hp\AppData\Roaming\Python\Python36\site-packages\speech_recognition_init_.py”, line 845, in recognize_google
response_text = response.read().decode(“utf-8”)
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x8b in position 1: invalid start byte

The code is as follows:

r = sr.Recognizer()
with sr.Microphone(1) as source:
 print("Say Something");
 r.adjust_for_ambient_noise(source, duration=1)
 audio = r.listen(source)
 print("Audio captured!")
 print("Time Over, Thanks")
 
try:
    str=r.recognize_google(audio)
    print("Text: "+ str);
except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e)) 
print('Recognition Ended')```

Can you guide me? I have tried the unicode function but its not working

Hi @Aishwarya, would you please surround your code with backticks to help readability?

Thanks for the reply.
I have done the same.