I have seen similar questions about my problem but they do not seem to help.
My code is
def take_command():
try:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'give' in command:
print('give mentioned')
comand = command.replace('give' '')
print(comand)
except:
pass
return command
def run_give():
command = take_command()
print(command)
The error is
Traceback (most recent call last):
File "c:\Users\REDACTED\REDACTED\REDACTED\REDACTED\main.py", line 72, in <module>
run_give()
File "c:\Users\REDACTED\REDACTED\REDACTED\REDACTED\main.py", line 38, in run_give
command = take_command()
File "c:\Users\REDACTED\REDACTED\REDACTED\REDACTED\main.py", line 34, in take_command
return command
UnboundLocalError: local variable 'command' referenced before assignment
I have tried many ways to fix it but nothing works. And yes I have these istalled for it to work
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes