From 63f926b5b18170944a5e3f98e9a06d987120a792 Mon Sep 17 00:00:00 2001 From: Ashfaaq Rifath Date: Sun, 15 May 2022 16:13:09 +0530 Subject: [PATCH] Update casper.py --- casper.py | 335 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 224 insertions(+), 111 deletions(-) diff --git a/casper.py b/casper.py index 6368e91..b2d5807 100644 --- a/casper.py +++ b/casper.py @@ -1,7 +1,7 @@ -import ctypes import speech_recognition as sr import pyttsx3 import os +import ctypes import subprocess import ctypes import winshell @@ -10,7 +10,6 @@ import wolframalpha import colorama import datetime -import playsound import time from tkinter import * from tkinter.ttk import * @@ -29,7 +28,8 @@ def casper_speak(speak, voice): engine.say(speak) engine.runAndWait() -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + def casper_listen(): r = sr.Recognizer() @@ -39,79 +39,100 @@ def casper_listen(): print("") text1 = "Listening...".center(100) print(Fore.YELLOW + text1) - audio = r.listen(source, phrase_time_limit = 15) + audio = r.listen(source, phrase_time_limit=15) print(Fore.BLUE + "Processing...".center(100)) try: - speech = r.recognize_google(audio, language='en-US') - print(f"(●) {speech}".center(100)) - return speech + u_said = r.recognize_google(audio, language='en-US') + print(f"(●) {u_said}".center(100)) + return u_said except: - print(Fore.LIGHTBLACK_EX + "Command not recieved, Stand by".center(100)) + print(Fore.LIGHTBLACK_EX + "Awaiting command.".center(100)) return 0 -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ -def open_application(command): + +def open_program(command): if "chrome" in command.lower(): print(Fore.GREEN + "Opening Google Chrome".center(100)) casper_speak(speak="Opening Google Chrome", voice=casper_voice) - os.startfile("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe") + os.startfile( + "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe") return elif "drive" in command: print(Fore.GREEN + "Opening Google Drive".center(100)) casper_speak(speak="Opening Google Drive", voice=casper_voice) - os.startfile("C:/Program Files/Google/Drive File Stream/56.0.11.0/GoogleDriveFS.exe") + os.startfile( + "C:/Program Files/Google/Drive File Stream/56.0.11.0/GoogleDriveFS.exe") return elif "code" in command.lower(): print(Fore.GREEN + "Opening Visual Studio Code".center(100)) casper_speak(speak="Opening Visual Studio Code", voice=casper_voice) - os.startfile("C:/Users/ashfa/AppData/Local/Programs/Microsoft VS Code/Code.exe") + os.startfile( + "C:/Users/ashfa/AppData/Local/Programs/Microsoft VS Code/Code.exe") return elif "downloader" in command or "video" in command.lower(): print(Fore.GREEN + "Opening YouTube Downloader".center(100)) casper_speak(speak="Opening YouTube Downloader", voice=casper_voice) - os.startfile("C:/Users/ashfa/OneDrive/Documents/VScode Projects/My YT Downloader/YTdownloader.exe") + os.startfile( + "C:/Users/ashfa/OneDrive/Documents/VScode Projects/My YT Downloader/YTdownloader.exe") return elif "word" in command: print(Fore.GREEN + "Opening Microsoft Word".center(100)) casper_speak(speak="Opening Microsoft Word", voice=casper_voice) - os.startfile("C:/Program Files (x86)/Microsoft Office/root/Office16/WINWORD.EXE") + os.startfile( + "C:/Program Files (x86)/Microsoft Office/root/Office16/WINWORD.EXE") return elif "excel" in command or "worksheet" in command: print(Fore.GREEN + "Opening Microsoft Excel".center(100)) casper_speak(speak="Opening Microsoft Excel", voice=casper_voice) - os.startfile("C:/Program Files (x86)/Microsoft Office/root/Office16/EXCEL.EXE") + os.startfile( + "C:/Program Files (x86)/Microsoft Office/root/Office16/EXCEL.EXE") return elif "access" in command or "database" in command: print(Fore.GREEN + "Opening Microsoft Access".center(100)) casper_speak(speak="Opening Microsoft Access", voice=casper_voice) - os.startfile("C:/Program Files (x86)/Microsoft Office/root/Office16/MSACCESS.EXE") + os.startfile( + "C:/Program Files (x86)/Microsoft Office/root/Office16/MSACCESS.EXE") + return + + elif "notepad" in command.lower(): + print(Fore.GREEN + "Opening Notepad".center(100)) + casper_speak(speak="Opening Notepad", voice=casper_voice) + os.startfile("%windir%/system32/notepad.exe") return elif "zoom" in command.lower(): print(Fore.GREEN + "Opening Zoom".center(100)) casper_speak(speak="Opening Zoom", voice=casper_voice) os.startfile("C:/Users/ashfa/AppData/Roaming/Zoom/bin/Zoom.exe") + return - elif "connect" in command: - print(Fore.LIGHTGREEN_EX + "Connecting to wifi".center(100)) - casper_speak(speak="connecting to wifi", voice=casper_voice) - subprocess.call([r'C:\Users\ashfa\OneDrive\Documents\Batch files\Wifi Shortcut.bat']) - print(Fore.GREEN + "connected wifi".center(100)) - casper_speak("connected wifi") + elif "activate VPN" in command: + print(Fore.GREEN + "Activating VPN sir".center(100)) + casper_speak(speak="Activating VPN sir", voice=casper_voice) + os.startfile( + "C:/Program Files (x86)/Windscribe/WindscribeLauncher.exe") return -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + elif "task manager" in command.lower(): + print(Fore.GREEN + "Accessing Task Manager".center(100)) + casper_speak(speak="Accessing Task Manager", voice=casper_voice) + os.startfile("%windir%/system32/taskmgr.exe /7") + return + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + -def close_application(command): +def close_program(command): if "chrome" in command: print(Fore.GREEN + "Closing Google Chrome".center(100)) casper_speak(speak="Closing Google Chrome", voice=casper_voice) @@ -130,7 +151,26 @@ def close_application(command): os.system("taskkill /f /im winword.exe") return -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + elif "code" in command.lower(): + print(Fore.GREEN + "Closing Visual Studio Code".center(100)) + casper_speak(speak="Closing Visual Studio Code", voice=casper_voice) + os.system("taskkill /f /im Code.exe") + return + + elif "close notepad" in command.lower(): + print(Fore.GREEN + "Understood sir".center(100)) + casper_speak(speak="Understood sir", voice=casper_voice) + os.system("taskkill /f /im notepad.exe") + return + + elif "close this" in command.lower(): + print(Fore.GREEN + "Understood sir".center(100)) + casper_speak(speak="Understood sir", voice=casper_voice) + os.system("taskkill /f /im notepad.exe") + return + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + def makeNote(take_note): date = datetime.datetime.now().strftime("%h:%H:%M:%S") @@ -140,17 +180,19 @@ def makeNote(take_note): subprocess.Popen(["notepad.exe", note_name]) -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + def say_time(): time = datetime.datetime.now().strftime("%H:%M:%S") print(Fore.GREEN + f"The time is {time} sir.".center(100)) - casper_speak(speak= f"The time is {time} sir.", voice=casper_voice) + casper_speak(speak=f"The time is {time} sir.", voice=casper_voice) + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ def knowledge(question): - #wolframalpha api ID + # wolframalpha api ID app_id = "Q3RGAU-UWQT2U8W2J" client = wolframalpha.Client(app_id) @@ -161,13 +203,16 @@ def knowledge(question): print(Fore.GREEN + wolfram_answer) casper_speak(speak=wolfram_answer, voice=casper_voice) -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + def windows_tasks(command): if "change background" in command.lower(): - ctypes.windll.user32.SystemParametersInfoW(20, 0, "C:/Users/ashfa/Downloads/Wallpapers/798915.png", 0) + ctypes.windll.user32.SystemParametersInfoW( + 20, 0, "C:/Users/ashfa/Downloads/Wallpapers/dtwall11.png", 0) print(Fore.GREEN + "Desktop background changed sir.".center(100)) - casper_speak(speak="Desktop background changed sir.", voice=casper_voice) + casper_speak(speak="Desktop background changed sir.", + voice=casper_voice) elif "empty bin" in command or "recycle" in command.lower(): winshell.recycle_bin().empty(confirm=False, show_progress=True, sound=True) @@ -176,30 +221,45 @@ def windows_tasks(command): elif "shutdown" in command.lower(): print(Fore.GREEN + "Windows will shutdown in T minus 60 seconds.".center(100)) - casper_speak(speak="Windows will shutdown in T minus 60 seconds.", voice=casper_voice) - print(Fore.MAGENTA + "Assistant power down, see you later sir.".center(100)) - casper_speak(speak="assistant power down, see you later sir.", voice=casper_voice) + casper_speak( + speak="Windows will shutdown in T minus 60 seconds.", voice=casper_voice) + print(Fore.MAGENTA + "System power down, see you later sir.".center(100)) + casper_speak(speak="System power down, see you later sir.", + voice=casper_voice) os.system("shutdown /s /t 60") - os.system("taskkill /f /im Code.exe") + os.system("taskkill /f /im python.exe") + + elif "restart" in command.lower(): + print(Fore.GREEN + "Restarting windows sir.".center(100)) + casper_speak(speak="Restarting windows sir.", voice=casper_voice) + print(Fore.MAGENTA + "System power down, see you later sir.".center(100)) + casper_speak(speak="System power down, see you later sir.", + voice=casper_voice) + os.system("taskkill /f /im python.exe") + subprocess.call(["shutdown", "/r"]) elif "sign out" in command or "log off" in command.lower(): print(Fore.GREEN + "Windown signing out sir.".center(100)) casper_speak(speak="Windown signing out sir.", voice=casper_voice) - print(Fore.MAGENTA + "Assistant power down, see you later sir.".center(100)) - casper_speak(speak="assistant power down, see you later sir.", voice=casper_voice) - os.system("taskkill /f /im Code.exe") + print(Fore.MAGENTA + "System power down, see you later sir.".center(100)) + casper_speak(speak="System power down, see you later sir.", + voice=casper_voice) + os.system("taskkill /f /im python.exe") subprocess.call(["shutdown", "/l"]) - -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + def search_web(command): if "youtube" in command.lower(): indx = command.lower().split().index("youtube") yt_search = command.split()[indx + 1:] print(Fore.GREEN + f"Searching YouTube for {yt_search}".center(100)) - casper_speak(speak=f"Searching YouTube for {yt_search}", voice=casper_voice) - webbrowser.open(f"http://www.youtube.com/results?search_query={yt_search}") - casper_speak(speak="I found this on YouTube", voice=casper_voice) + casper_speak( + speak=f"Searching YouTube for {yt_search}", voice=casper_voice) + webbrowser.open( + f"http://www.youtube.com/results?search_query={yt_search}") + casper_speak(speak="I found these results", voice=casper_voice) return elif "wikipedia" in command.lower(): @@ -207,15 +267,18 @@ def search_web(command): casper_speak(speak="what do you want to search?", voice=casper_voice) wiki_search = casper_listen() - print(Fore.GREEN + f"Searching wikipedia for {wiki_search}".center(100)) - casper_speak(speak=f"searching wikipedia for {wiki_search}", voice=casper_voice) + print(Fore.GREEN + + f"Searching wikipedia for {wiki_search}".center(100)) + casper_speak( + speak=f"searching wikipedia for {wiki_search}", voice=casper_voice) wiki_summary = wikipedia.summary(wiki_search, sentences=2) centr = str(wiki_summary) webbrowser.open(f"https://en.wikipedia.org/wiki/{wiki_search}") print(" ") print(Fore.LIGHTBLUE_EX + centr.center(100)) - casper_speak(speak=f"According to wikipedia, {wiki_summary}", voice=casper_voice) + casper_speak( + speak=f"According to wikipedia, {wiki_summary}", voice=casper_voice) return elif "github" in command or "account" in command.lower(): @@ -226,26 +289,29 @@ def search_web(command): elif "source code" in command.lower(): print(Fore.GREEN + "Accessing source code from GitHub".center(100)) - casper_speak(speak="Accessing source code from GitHub", voice=casper_voice) + casper_speak(speak="Accessing source code from GitHub", + voice=casper_voice) webbrowser.open("https://github.com/ashfaaqrifath/Casper") return elif "stack overflow" in command.lower(): print(Fore.GREEN + "Opening Stack Overflow".center(100)) casper_speak(speak="Opening Stack Overflow", voice=casper_voice) - webbrowser.open("https://stackoverflow.com/questions/tagged/python+python-3.x+visual-studio-code?sort=Newest&uqlId=57773") - #This link is with my stackoverflow filter. + webbrowser.open( + "https://stackoverflow.com/questions/tagged/python+python-3.x+visual-studio-code?sort=Newest&uqlId=57773") + # This link is with my stackoverflow filter. return elif "search" in command.lower(): indx = command.lower().split().index("search") query = command.split()[indx + 1:] print(Fore.GREEN + f"Searching Google for {query}".center(100)) - casper_speak(speak= f"searching google for {query}", voice=casper_voice) + casper_speak(speak=f"searching google for {query}", voice=casper_voice) webbrowser.open(f"http://www.google.com/search?q={query}") + casper_speak(speak="I found these results", voice=casper_voice) return - elif "new tab" in command or "chrome tab" in command.lower(): + elif "new tab" in command or "chrome tab" in command.lower(): webbrowser.open("https://google.com") print(Fore.GREEN + "Opened new chrome tab".center(100)) casper_speak(speak="opened new chrome tab", voice=casper_voice) @@ -268,21 +334,24 @@ def search_web(command): casper_speak(speak=f"{google_maps} Located sir.", voice=casper_voice) return -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + def play_music(): print(Fore.GREEN + "Playing music from music directory".center(100)) - casper_speak(speak="Playing music from music directory", voice=casper_voice) + casper_speak(speak="Playing music from music directory", + voice=casper_voice) music_dir = "C:/Users/ashfa/Music" songs = os.listdir(music_dir) os.startfile(os.path.join(music_dir, songs[1])) return -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ -def takeCommand(command): + +def command_engine(command): try: -#Internet stuff + # Internet stuff if "search" in command or "where is" in command or "YouTube" in command or "wikipedia" in command.lower(): search_web(command) return @@ -307,22 +376,28 @@ def takeCommand(command): search_web(command) return -#WolframAlpha API + elif "password" in command.lower(): + subprocess.call("password_manager.py", shell=True) + return + +# WolframAlpha API elif "knowledge" in command: print(Fore.YELLOW + "what do you want to know about?".center(100)) - casper_speak(speak="what do you want to know about?", voice=casper_voice) + casper_speak(speak="what do you want to know about?", + voice=casper_voice) get_query = casper_listen() knowledge(get_query) return -#windows stuff +# windows stuff elif "play music" in command.lower(): play_music() return elif "write" in command or "not" in command.lower(): print(Fore.YELLOW + "What would you like me to write down sir? ".center(100)) - casper_speak(speak="What would you like me to write down sir? ", voice=casper_voice) + casper_speak( + speak="What would you like me to write down sir? ", voice=casper_voice) write_note = casper_listen() makeNote(write_note) print(Fore.GREEN + "I've made a note of that.".center(100)) @@ -345,35 +420,40 @@ def takeCommand(command): windows_tasks(command) return -#opening applications,closing,wifi +# opening applications,closing elif "open" in command.lower(): - open_application(command.lower()) + open_program(command.lower()) return - + elif "close" in command.lower(): - close_application(command.lower()) + close_program(command.lower()) return - elif "connect" in command.lower(): - open_application(command.lower()) + elif "activate VPN" in command: + open_program(command) return -#telling the time + elif "task manager" in command.lower(): + open_program(command.lower()) + return + +# telling the time elif "time" in command.lower(): say_time() return -#changing the voice of Casper - elif "voice" in command: +# changing the voice of Casper + elif "voice" in command: print(Fore.GREEN + "Voice engine changed.".center(100)) casper_speak(speak="Voice engine changed.", voice=casper_voice) -#stop Casper from taking commands for 2mins - elif "stop" in command or "listening" in command or "disable" in command.lower(): - print(Fore.GREEN + "Speech recognition enabled.".center(100)) - casper_speak(speak="Speech recognition enabled", voice=casper_voice) +# stop Casper from taking commands for 2mins + # elif "stop" in command or "listening" in command or "disable" in command.lower(): + # print(Fore.GREEN + "Speech recognition enabled.".center(100)) + # casper_speak(speak="Speech recognition enabled", + # voice=casper_voice) -#Casper responses (hardcoded) +# Casper responses (hardcoded) elif "introduce" in command: casperIntro1 = "I'm Casper, version 2 point 0, your virtual desktop assistant." print(Fore.CYAN + casperIntro1.center(100)) @@ -381,27 +461,35 @@ def takeCommand(command): elif "what's my name" in command or "what is my name" in command.lower(): print(Fore.GREEN + "Your name is Ashfaaq Rifath.".center(100)) - casper_speak(speak="Your name is Ashfaaq Rifath.", voice=casper_voice) + casper_speak(speak="Your name is Ashfaaq Rifath.", + voice=casper_voice) elif "who made you" in command: print(Fore.GREEN + "I was developed by Ashfaaq Rifath.".center(100)) - casper_speak(speak="i was developed by Ashfaaq Rifath.", voice=casper_voice) + casper_speak(speak="i was developed by Ashfaaq Rifath.", + voice=casper_voice) elif "what's up" in command or "how are you" in command.lower(): print(Fore.CYAN + "I'm fine sir, thank you for asking.".center(100)) - casper_speak(speak="i'm fine sir, thank you for asking.", voice=casper_voice) + casper_speak( + speak="i'm fine sir, thank you for asking.", voice=casper_voice) elif "singularity" in command.lower(): - print("Chances of me reaching the technological singularity is very low sir.".center(100)) - casper_speak(speak="Chances of me reaching the technological singularity is very low sir.", voice=casper_voice) + print( + "Chances of me reaching the technological singularity is very low sir.".center(100)) + casper_speak( + speak="Chances of me reaching the technological singularity is very low sir.", voice=casper_voice) elif "thank you" in command: - print(Fore.CYAN + "You're welcome, i'm happy to help sir".center(100)) - casper_speak(speak="you're welcome, i'm happy to help sir", voice=casper_voice) + print(Fore.CYAN + "You're welcome sir, i'm happy to help.".center(100)) + casper_speak( + speak="you're welcome sir, i'm happy to help.", voice=casper_voice) elif "useless" in command: - print(Fore.RED + "Whatever, you're a pathetic excuse for a human being.".center(100)) - casper_speak(speak="whatever, you're a pathetic excuse for a human being.", voice=casper_voice) + print( + Fore.RED + "Whatever, you're a pathetic excuse for a human being.".center(100)) + casper_speak( + speak="whatever, you're a pathetic excuse for a human being.", voice=casper_voice) elif "named after" in command: casperIntro2 = "I was named after the cat of my developer." @@ -409,12 +497,16 @@ def takeCommand(command): casper_speak(speak=casperIntro2, voice=casper_voice) elif "sri lanka" in command.lower(): - print(Fore.RED + "Sri lanka is a pathetic excuse for a country....sorry, island.".center(100)) - casper_speak(speak="Sri lanka is a pathetic excuse for a country....sorry, island.", voice=casper_voice) + print( + Fore.RED + "Sri lanka is a pathetic excuse for a country....sorry, island.".center(100)) + casper_speak( + speak="Sri lanka is a pathetic excuse for a country....sorry, island.", voice=casper_voice) else: - print(Fore.MAGENTA + "I can search the web for you, Do you want to continue?".center(100)) - casper_speak(speak="I can search the web for you, Do you want to continue?", voice=casper_voice) + print( + Fore.MAGENTA + "I can search the web for you, Do you want to continue?".center(100)) + casper_speak( + speak="I can search the web for you, Do you want to continue?", voice=casper_voice) answer = casper_listen() if "yes" in str(answer) or "yeah" in str(answer).lower(): search_web(command) @@ -422,11 +514,11 @@ def takeCommand(command): return except: - print(Fore.RED + "Sorry, command not defined, please try again!".center(100)) - casper_speak(speak="sorry, command not defined, please try again!", voice=casper_voice) - -#█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + print(Fore.RED + "Sorry, i didn't get that, please try again!".center(100)) + casper_speak( + speak="Sorry, i didn't get that, please try again!", voice=casper_voice) +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ if __name__ == "__main__": @@ -436,10 +528,10 @@ def takeCommand(command): # symbol = width * percent // 100 # blanks = width - symbol - # print('\r[ ', Fore.GREEN + symbol*'█', blanks*' ', ' ]', f' {percent:.0f}%', sep='', + # print('\r[ ', Fore.GREEN + symbol* "█", blanks*' ', ' ]', f' {percent:.0f}%', sep='', # end='', flush=True) - # print(Fore.YELLOW + " Launching Casper v2.1.0") + # print(Fore.YELLOW + " Launching Casper v2.3.0") # for i in range(101): # progress(i) # sleep(0.01) @@ -447,15 +539,14 @@ def takeCommand(command): # print() # print(Fore.BLUE + " Systems ready") # print(" ") +# uncomment the above code to enable cmd progress bar. - #uncomment the above code to enable cmd progress bar. - - casper_voice = 3 + casper_voice = 2 print(Fore.GREEN + ''' ░█▀▀█ ░█▀▀█ ░█▀▀▀█ ░█▀▀█ ░█▀▀▀ ░█▀▀█ ░█ ░█▄▄█ ▀▀▀▄▄ ░█▄▄█ ░█▀▀▀ ░█▄▄▀ - ░█▄▄█ ░█ ░█ ░█▄▄▄█ ░█ ░█▄▄▄ ░█ ░█ ver 2.1.0 + ░█▄▄█ ░█ ░█ ░█▄▄▄█ ░█ ░█▄▄▄ ░█ ░█ ver 2.3.0 DESKTOP ASSISTANT''') print(" ") @@ -465,7 +556,7 @@ def takeCommand(command): print(Fore.CYAN + greet.center(100)) elif nowTime >= 12 and nowTime < 18: - greet = "Good Afternooon sir, what can i do for you?" + greet = "Good Afternoon sir, what can i do for you?" print(Fore.CYAN + greet.center(100)) else: @@ -478,22 +569,44 @@ def takeCommand(command): recognize = casper_listen() if recognize == 0: continue - + if "voice" in str(recognize): if "change" in str(recognize): - casper_voice = 2 + casper_voice = 1 if "default" in str(recognize): - casper_voice = 3 + casper_voice = 2 - elif "stop" in str(recognize): - print(Fore.LIGHTRED_EX + "Speech recognition disabled for 2 minutes.".center(100)) - casper_speak(speak="speech recognition disabled for 2 minutes.", voice=casper_voice) - time.sleep(120) + elif "stand by" in str(recognize): + print(Fore.LIGHTRED_EX +"Standby Mode initiated.".center(100)) + casper_speak(speak="Standby mode initiated.", voice=casper_voice) + print(Fore.LIGHTBLACK_EX + "Awaiting wake command.".center(100)) + + def wake(): + r = sr.Recognizer() + with sr.Microphone() as source: + standby = r.listen(source) + wake_command = "" + + try: + wake_command = r.recognize_google(standby) + print(f"(●) {wake_command}".center(100)) + except Exception as e: + pass + return wake_command.lower() + + WAKE = "hello" + while True: + keyword = wake() + if keyword.count(WAKE) > 0: + print(Fore.LIGHTBLACK_EX + "Hello sir, how can i help".center(100)) + casper_speak(speak="Hello sir, how can i help", voice=casper_voice) + keyword = casper_listen() + break if "sleep" in str(recognize): - print(Fore.MAGENTA + "Assistant power down, see you later sir.".center(100)) - casper_speak(speak="assistant power down, see you later sir.", voice=casper_voice) + print(Fore.MAGENTA + "System power down, see you later sir.".center(100)) + casper_speak( + speak="System power down, see you later sir.", voice=casper_voice) exit() - #break - takeCommand(recognize) \ No newline at end of file + command_engine(recognize)