My program is working perfectly fine but I am having speed problems. It takes too long to respond and give results. After 2,3 runs it takes more time than before. Also additionally it takes lots of time to start. What are the ways to speed up of program? I am new in this field.
# Imported speech recognition as sr, pyttsx3, pywhatkit, datetime, pyjokes, os
listener = sr.Recognizer()
engine = pyttsx3.init()
def talk(text):
engine.say(text)
engine.runAndWait()
talk('Hello what can i do for you')
def take_command():
try:
with sr.Microphone() as source:
print("Listening...")
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if "jarvis" in command:
command = command.replace('jarvis', '')
return command
else:
talk("I cannot continue until you say jarvis")
take_command()
except:
pass
def run_jarvis():
command = take_command()
if not command:
take_command()
else:
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(time)
elif 'joke' in command:
joke = pyjokes.get_joke()
print(joke)
talk(joke)
elif 'downloads' in command:
path = "C:/Users\Mayur\Downloads"
path = os.path.realpath(path)
os.startfile(path)
elif "whatsapp" in command:
msg = command.replace("whatsapp", "")
pywhatkit.sendwhatmsg_instantly("+91xxxxxxxxxx", msg)
print("Successfully Sent!")
talk("successfully sent")
elif 'who is' or 'what is' or 'where is' or 'when is' or 'information' or 'which is' or "how is" in command:
result = pywhatkit.info(command, 3, True)
talk(result)
print(result)
else:
talk('Sorry sir can you repeat again')
while True:
run_jarvis()