Open ThisIsArnav opened 3 years ago
install the required packages needed for this project correctly
yeah I have the same problem and I installed all the packages completely this is problem that shows after running the code Traceback (most recent call last): File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 70, in run_python() File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 35, in run_python command = take_command() File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 31, in take_command return command UnboundLocalError: local variable 'command' referenced before `assignment```
See My Code? scroll a bit Error: Traceback (most recent call last): File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 70, in
run_python()
File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 35, in run_python
command = take_command()
File "D:/Coding/Fun With Python/PyCharm/PyCharm Projects/Virtual Assistant/main.py", line 31, in take_command
return command
UnboundLocalError: local variable 'command' referenced before `assignment```
And my Code is: import speech_recognition as sr import pyttsx3 import pywhatkit import datetime import wikipedia import pyjokes
listener = sr.Recognizer() engine = pyttsx3.init() voices = engine.getProperty('voices') engine.setProperty('voice', voices[0].id)
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 'python' in command: command = command.replace('python', '') print(command) except: pass return command
def run_python(): command = take_command() print(command) if 'play' in command: song = command.replace('play', '') talk('playing' + song) pywhatkit.playonyt(song) elif 'time' in command: time = datetime.datetime.now().strftime('%I:%M %p') print(time) talk('The time is' + time) elif 'what is' in command: query = command.replace('what is', '') info = wikipedia.summary(query, 1) print(info) talk(info) elif 'who is' in command: person = command.replace('who is', '') info = wikipedia.summary(person, 1) print(info) talk(info) elif 'your name' in command: talk("Hi My Name Is Python") elif 'created you' in command: talk('Tanush has created me') elif 'joke' in command: talk(pyjokes.get_joke()) elif 'shut up' in command: talk('quitting') exit() else: print("Could you repeat it again?") talk('Could you repeat it again')
while True: run_python()