Hello everyone I am trying to develop a virtual assistant which will help me with some projects so I am trying to get the basics for the final project however I get an error (UnboundLocalError: local variable 'command' referenced before assignment) and I tried to change return command
to under the printf(command)
but it does not let me talk and a message NONE and the other error which is (TypeError: argument of type 'NoneType' is not iterable) appears on the terminal.
So how can I make this work without stop?
CODE BELOW:
import pyttsx3
import pywhatkit
import datetime
listener = sr.Recognizer()
engine = pyttsx3.init()
def talk(text):
engine.say(text)
engine.runAndWait()
def take_command():
try:
with sr.Microphone() as source:
print('listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'skor' in command:
command = command.replace ('skor', '')
print(command)
except:
pass
return command
def run_skor():
command = take_command()
print(command)
if 'play on youtube' in command:
song = command.replace ('play on youtube', '')
talk('playing' + song)
pywhatkit.playonyt(song)
elif 'search on google' in command:
sea = command.replace ('search on google', '')
talk ('searching' + sea)
pywhatkit.search(sea)
elif 'tell me the time' in command:
time = datetime.datetime.now().strftime('%H:%M')
print(time)
talk('Current time is' + time)
while True:
run_skor()```