Just remove
Function should take argument in and not just get it magically from global namespace.
If i do quick test and take out Microphone as i have not set it up.
So i want it to tell a joke.
try/except
in take_command()
function.Function should take argument in and not just get it magically from global namespace.
If i do quick test and take out Microphone as i have not set it up.
So i want it to tell a joke.
import speech_recognition as sr import pyttsx3 import pywhatkit import datetime import wikipedia import pyjokes import random as rd thx1 = ["Your Welcome", "No problem", "Its my job to help you"] listener = sr.Recognizer() engine = pyttsx3.init() voices = engine.getProperty('voices') engine.setProperty('voice', voices[1].id) def talk(text): engine.say(text) engine.runAndWait() print("Im Ava what can i do for you?") talk("Im Ava... what can i do for you?") print("If you need any help say help") talk("If you need any help say help") def take_command(): ''' with sr.Microphone() as source: print("Listening...") voice = listener.listen(source) command = listener.recognize_google(voice) command = command.lower() print(command) if 'ava' in command: command = command.replace('ava', '') ''' return 'time' def run_ava(take_command): command = take_command() if 'play99' in command: song = command.replace('play', '') talk('playing' + song) pywhatkit.playonyt(song) elif 'help' in command: print("Here is what i can: play music on youtube, search something on wiki, tell jokes, tell time now") talk('Here is what i can') elif 'hear me' in command: print("Yes, I can hear you clear") talk("Yes, I can hear you clear") elif 'who are you' in command: print('Im Ava your virtual assistent') talk('Im Ava... your virtual assistent') elif 'how are you' in command: print("Im glad you asked. Im good thank you") talk("Im glad you asked. Im good thank you") elif 'thanks' in command: thx = rd.choice(thx1) print(thx) talk(thx) elif 'thank you' in command: thx = rd.choice(thx1) print(thx) talk(thx) elif 'male or female' in command: print('Male, Female, Nonbinary? Nah bro im a walmart bag') talk('male... female... nonbinary? nah broo.. im a walmart bag') elif 'time' in command: time = datetime.datetime.now().strftime('%H:%M') print(time) talk('Its' + time) elif 'tell me something about' in command: person = command.replace('tell me something about' , '') info = wikipedia.summary(person, 5) print(info) talk(info) elif 'who is' in command: person = command.replace('who is' , '') info = wikipedia.summary(person, 5) print(info) talk(info) elif 'what is' in command: person = command.replace('what is' , '') info = wikipedia.summary(person, 5) print(info) talk(info) elif 'joke' in command: joke = pyjokes.get_joke() print(joke) talk(joke) else: talk('Im not sure i understand') run_ava(take_command)
Output:(dl_env) G:\div_code\dl_env
λ python speak.py
Im Ava what can i do for you?
If you need any help say help
If you play a Windows CD backwards, you'll hear satanic chanting ... worse still, if you play it forwards, it installs Windows.