I have made a web browser by using python and I need to use speech recognition to control it (eg: open a tab, Close a tab, type Url)
import speech_recognition as sr
listener = sr.Recognizer()
class VoiceRecognition():
def take_command(self):
try:
while True:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
print(command)
except:
pass
return command
This is the code for speech recognition
But when I use an object and call the take_command() function inside the web browser code it gives an error.
UnboundLocalError: local variable 'command' referenced before assignment
please help me.