diff --git a/PC_functions.py b/PC_functions.py new file mode 100644 index 0000000..f017081 --- /dev/null +++ b/PC_functions.py @@ -0,0 +1,46 @@ +import os +import winshell +import subprocess +import ctypes +import colorama +from speech_engine import casper_speak +from colorama import Fore, Back +colorama.init(autoreset=True) + + +def windows_tasks(command, voice_var): + if "change background" in command.lower(): + 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=voice_var) + + elif "clear" in command or "recycle" in command.lower(): + winshell.recycle_bin().empty(confirm=False, show_progress=True, sound=True) + print(Fore.GREEN + "Recycle bin cleared sir.".center(100)) + casper_speak(speak="Recycle bin cleared sir.", voice=voice_var) + + 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=voice_var) + print(Fore.MAGENTA + "System power down, see you later sir.".center(100)) + casper_speak(speak="System power down, see you later sir.", voice=voice_var) + os.system("shutdown /s /t 60") + 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=voice_var) + print(Fore.MAGENTA + "System power down, see you later sir.".center(100)) + casper_speak(speak="System power down, see you later sir.", voice=voice_var) + subprocess.call(["shutdown", "/r"]) + os.system("taskkill /f /im python.exe") + + elif "sign out" in command or "log off" in command.lower(): + print(Fore.GREEN + "Windows signing out.".center(100)) + casper_speak(speak="Windows signing out.", voice=voice_var) + print(Fore.MAGENTA + "System power down, see you later sir.".center(100)) + casper_speak(speak="System power down, see you later sir.", voice=voice_var) + subprocess.call(["shutdown", "/l"]) + os.system("taskkill /f /im python.exe") \ No newline at end of file diff --git a/activity_log.py b/activity_log.py new file mode 100644 index 0000000..45a654c --- /dev/null +++ b/activity_log.py @@ -0,0 +1,22 @@ +import sys +import os +import datetime + +date = datetime.datetime.now().strftime("%h:%H:%M:%S") +log_name = str(date).replace(":", "-") + "-Log.txt" +folder = "Casper Log" +save_path = os.path.join(folder, log_name) + + +def casper_log(write): + print_save = sys.stdout + f = open(save_path, 'a', encoding="utf-8") + sys.stdout = f + y = write + y = write + y = write + + print(y) + + sys.stdout = print_save + f.close() \ No newline at end of file diff --git a/casper.py b/casper.py new file mode 100644 index 0000000..1f5ea89 --- /dev/null +++ b/casper.py @@ -0,0 +1,389 @@ +import speech_recognition as sr +import pyttsx3 +import os +import ctypes +import subprocess +import sys +import winshell +import webbrowser +import wikipedia +import wolframalpha +import colorama +import datetime +import time +from tkinter import * +from tkinter.ttk import * +from tkinter.filedialog import askopenfile +from time import sleep +from gtts import gTTS +from speech_engine import casper_speak +from PC_functions import windows_tasks +from web_functions import search_web +from open_program import open_program +from close_program import close_program +from launch import launching +from colorama import Fore, Back +colorama.init(autoreset=True) + + +date = datetime.datetime.now().strftime("%h:%H:%M:%S") +log_name = str(date).replace(":", "-") + "-Log.txt" +folder = "Casper Log" +save_path = os.path.join(folder, log_name) + +log_file = open(save_path, "a") +date = datetime.datetime.now() +h = "\n" + str(date) + " \n<<< CASPER ACTIVITY LOG >>> \nBEGIN LOG >>>\n \n" +log_file.write(h) +log_file.close() + + +def casper_log(write): + print_save = sys.stdout + f = open(save_path, 'a', encoding="utf-8") + sys.stdout = f + y = write + y = write + y = write + + print(y) + + sys.stdout = print_save + f.close() + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + +def casper_listen(): + r = sr.Recognizer() + audio = "" + with sr.Microphone() as source: + # print("") + #print(Fore.YELLOW + "Listening...".center(100)) + audio = r.listen(source, phrase_time_limit=15) + #print(Fore.BLUE + "Processing...".center(100)) + try: + u_said = r.recognize_google(audio, language='en-US') + print(Fore.BLUE + "Processing...".center(100)) + print(f"(●) {u_said}".center(100)) + + casper_log(Fore.BLUE + "Processing...".center(100)) + casper_log(f"(●) {u_said}".center(100)) + return u_said + except: + #print(Fore.LIGHTBLACK_EX + "Awaiting command.".center(100)) + return 0 + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + +def makeNote(take_note): + date = datetime.datetime.now().strftime("%h:%H:%M:%S") + note_name = str(date).replace(":", "-") + "-note.txt" + with open(note_name, "w") as noteFile: + noteFile.write(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=voice_engine) + + casper_log(Fore.GREEN + f"The time is {time} sir.".center(100)) + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + +def knowledge(question): + # wolframalpha api ID + app_id = "Q3RGAU-UWQT2U8W2J" + + client = wolframalpha.Client(app_id) + result = client.query(question) + wolfram_answer = next(result.results).text + + print() + print(Fore.GREEN + wolfram_answer + "".center(100)) + casper_speak(speak=wolfram_answer, voice=voice_engine) + + casper_log("") + casper_log(Fore.GREEN + wolfram_answer + "".center(100)) + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + +def play_music(): + print(Fore.GREEN + "Playing music from music directory".center(100)) + casper_speak(speak="Playing music from music directory", voice=voice_engine) + music_dir = "C:/Users/ashfa/Music" + songs = os.listdir(music_dir) + os.startfile(os.path.join(music_dir, songs[1])) + + casper_log(Fore.GREEN + "Playing music from music directory".center(100)) + return + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + + +def command_engine(command): + try: +# Internet stuff + if "search" in command or "where is" in command or "YouTube" in command or "wikipedia" in command.lower(): + search_web(command, voice_var=voice_engine) + return + + elif "new tab" in command or "chrome tab" in command or "incognito" in command.lower(): + search_web(command, voice_var=voice_engine) + return + + elif "account" in command: + search_web(command, voice_var=voice_engine) + return + + elif "stack overflow" in command: + search_web(command, voice_var=voice_engine) + return + + elif "source code" in command: + search_web(command, voice_var=voice_engine) + return + + elif "stackoverflow" in command.lower(): + search_web(command, voice_var=voice_engine) + return + + elif "password" in command.lower(): + subprocess.call("password_manager.py", shell=True) + return + +# WolframAlpha knowledge engine 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=voice_engine) + get_query = casper_listen() + knowledge(get_query) + + casper_log(Fore.YELLOW + "what do you want to know about?".center(100)) + return + +# 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=voice_engine) + write_note = casper_listen() + makeNote(write_note) + print(Fore.GREEN + "I've made a note of that.".center(100)) + casper_speak(speak="I've made a note of that.", voice=voice_engine) + + casper_log(Fore.YELLOW + "What would you like me to write down sir? ".center(100)) + casper_log(Fore.GREEN + "I've made a note of that.".center(100)) + return + + elif "change background" in command.lower(): + windows_tasks(command, voice_var=voice_engine) + return + + elif "clear" in command or "recycle" in command.lower(): + windows_tasks(command, voice_var=voice_engine) + return + + elif "shutdown" in command.lower(): + windows_tasks(command, voice_var=voice_engine) + return + + elif "sign out" in command or "log off" in command.lower(): + windows_tasks(command, voice_var=voice_engine) + return + +# opening applications,closing + elif "open" in command.lower(): + open_program(command.lower(), voice_var=voice_engine) + return + + elif "close" in command.lower(): + close_program(command.lower(), voice_var=voice_engine) + return + + elif "activate VPN" in command: + open_program(command, voice_var=voice_engine) + return + + elif "task manager" in command.lower(): + open_program(command.lower(), voice_var=voice_engine) + return + +# telling the time + elif "time" in command.lower(): + say_time() + return + +# changing the voice of Casper + elif "voice" in command: + print(Fore.GREEN + "Voice engine changed.".center(100)) + casper_speak(speak="Voice engine changed.", voice=voice_engine) + + casper_log(Fore.GREEN + "Voice engine changed.".center(100)) + +# Casper responses (hardcoded) + elif "introduce" in command: + casperIntro1 = "I'm Casper, version 2 point 5, your personal desktop assistant." + print(Fore.CYAN + casperIntro1.center(100)) + casper_speak(speak=casperIntro1, voice=voice_engine) + + casper_log(Fore.CYAN + casperIntro1.center(100)) + + 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=voice_engine) + + casper_log(Fore.GREEN + "Your name is Ashfaaq Rifath.".center(100)) + + 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=voice_engine) + + casper_log(Fore.GREEN + "I was developed by Ashfaaq Rifath.".center(100)) + + 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=voice_engine) + + casper_log(Fore.CYAN + "I'm fine sir, thank you for asking.".center(100)) + + elif "hi" in command or "hello" in command.lower(): + print(Fore.CYAN + "Hello sir, How can i help.".center(100)) + casper_speak(speak="Hello sir, How can i help.", voice=voice_engine) + + casper_log(Fore.CYAN + "Hello sir, How can i help.".center(100)) + + elif "thank you" in command: + 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=voice_engine) + + casper_log(Fore.CYAN + "Hello sir, How can i help.".center(100)) + + elif "useless" in command: + print(Fore.RED + "Whatever, you're a disgrace to the human race sir.".center(100)) + casper_speak(speak="Whatever, you're a disgrace to the human race sir", voice=voice_engine) + + casper_log(Fore.RED + "Whatever, you're a disgrace to the human race sir.".center(100)) + + elif "named after" in command: + casperIntro2 = "I was named after the cat of my developer." + print(Fore.CYAN + casperIntro2.center(100)) + casper_speak(speak=casperIntro2, voice=voice_engine) + + casper_log(Fore.CYAN + casperIntro2.center(100)) + + else: + print(Fore.RED + "Sorry sir, I didn't quite get that, please try again!".center(100)) + casper_speak(speak="Sorry sir, I didn't quite get that, please try again!", voice=voice_engine) + + casper_log(Fore.RED + "Sorry sir, I didn't quite get that, please try again!".center(100)) + + except: + print(Fore.RED + "Sorry sir, I didn't quite get that, please try again!".center(100)) + casper_speak(speak="Sorry sir, I didn't quite get that, please try again!", voice=voice_engine) + + casper_log(Fore.RED + "Sorry sir, I didn't quite get that, please try again!".center(100)) + +# █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ + + +if __name__ == "__main__": + launching() + voice_engine = 2 + + print("") + print(''' + █▀▀█ █▀▀█ █▀▀▀█ █▀▀█ █▀▀▀ █▀▀█ + █ █▄▄█ ▀▀▀▄▄ █▄▄█ █▀▀▀ █▄▄▀ + █▄▄█ █ █ █▄▄▄█ █ █▄▄▄ █ █ v2.5.0 + ''') + + nowTime = int(datetime.datetime.now().hour) + if nowTime >= 0 and nowTime < 12: + greet = "Good Morning sir, what can i do for you?" + print(Fore.CYAN + greet.center(100)) + casper_log(Fore.CYAN + greet.center(100)) + + elif nowTime >= 12 and nowTime < 18: + greet = "Good Afternoon sir, what can i do for you?" + print(Fore.CYAN + greet.center(100)) + casper_log(Fore.CYAN + greet.center(100)) + + else: + greet = "Good Evening sir, what can i do for you?" + print(Fore.CYAN + greet.center(100)) + casper_log(Fore.CYAN + greet.center(100)) + + casper_speak(speak=greet, voice=voice_engine) + print("") + print(Fore.YELLOW + "Listening...".center(100)) + + casper_log(Fore.YELLOW + "Listening...".center(100)) + + while(1): + recognize = casper_listen() + if recognize == 0: + continue + + if "voice" in str(recognize): + if "change" in str(recognize): + voice_engine = 1 + if "default" in str(recognize): + voice_engine = 2 + + elif "stand by" in str(recognize): + print(Fore.LIGHTRED_EX + "Initiated Standby Mode.".center(100)) + casper_speak(speak="initiated Standby mode.", voice=voice_engine) + print(Fore.LIGHTBLACK_EX + "Awaiting wake command.".center(100)) + + casper_log(Fore.LIGHTRED_EX + "Initiated Standby Mode.".center(100)) + casper_log(Fore.LIGHTBLACK_EX + "Awaiting wake command.".center(100)) + + def standBy(): + r = sr.Recognizer() + with sr.Microphone() as source: + wake = r.listen(source) + wake_command = "" + try: + wake_command = r.recognize_google(wake) + print(f"(●) {wake_command}".center(100)) + casper_log(f"(●) {wake_command}".center(100)) + except Exception as e: + pass + return wake_command.lower() + + WAKE = "hello" + while True: + keyword = standBy() + 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=voice_engine) + print("") + print(Fore.YELLOW + "Listening...".center(100)) + recognize = casper_listen() + + casper_log(Fore.LIGHTBLACK_EX + "Hello sir, how can i help".center(100)) + casper_log("") + casper_log(Fore.YELLOW + "Listening...".center(100)) + break + + if "sleep" in str(recognize): + print(Fore.MAGENTA + "System power down, see you later sir.".center(100)) + casper_speak(speak="System power down, see you later sir.", voice=voice_engine) + + casper_log(Fore.MAGENTA + "System power down, see you later sir.".center(100)) + casper_log("") + casper_log("END LOG >>>") + exit() + + command_engine(recognize) + print("") + print(Fore.YELLOW + "Listening...".center(100)) + + casper_log("") + casper_log(Fore.YELLOW + "Listening...".center(100)) \ No newline at end of file diff --git a/close_program.py b/close_program.py new file mode 100644 index 0000000..e11d115 --- /dev/null +++ b/close_program.py @@ -0,0 +1,43 @@ +import os +import colorama +from speech_engine import casper_speak +from colorama import Fore, Back +colorama.init(autoreset=True) + + +def close_program(command, voice_var): + if "chrome" in command: + print(Fore.GREEN + "Closing Google Chrome".center(100)) + casper_speak(speak="Closing Google Chrome", voice=voice_var) + os.system("taskkill /f /im chrome.exe") + return + + elif "excel" in command or "worksheet" in command: + print(Fore.GREEN + "Closing Microsoft Excel".center(100)) + casper_speak(speak="Closing Microsoft Excel", voice=voice_var) + os.system("taskkill /f /im excel.exe") + return + + elif "word" in command: + print(Fore.GREEN + "Closing Microsoft Word".center(100)) + casper_speak(speak="Closing Microsoft Word", voice=voice_var) + 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=voice_var) + 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=voice_var) + 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=voice_var) + os.system("taskkill /f /im notepad.exe") + return \ No newline at end of file diff --git a/launch.py b/launch.py new file mode 100644 index 0000000..1eb7ad6 --- /dev/null +++ b/launch.py @@ -0,0 +1,54 @@ +import time +import sys +import os +from colorama import Fore, Back +import colorama +colorama.init(autoreset=True) + + +def progress(percent=0, width=30): + symbol = width * percent // 100 + blanks = width - symbol + + print('\r [', Fore.GREEN + symbol * "█", blanks*' ', ']', f' {percent:.0f}%', + sep='', flush=True, end='') + +def launching(): + print(Fore.LIGHTBLACK_EX + ''' :!&@@@@@@@@@@@&!: + :Y#@@@@@@@@@@@@@@@@@@@#Y^ + .Y&@@@@@@@@@@@@@@@@@@@@@@@@@&5. + :G@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@B: + 5@@@@#: 75B&@@@&&#B#&@@@@&B57 ^&@@@@5 + .#@@@@@5 .. .. G@@@@@&. + &@@@@@@5 G@@@@@@&. + B@@@@@@@5 .:. .:. G@@@@@@@B + ^@@@@@@@@5 .B@@@@J J@@@@B. G@@@@@@@@~ + P@@@@@@@@5 ?@@@@@@ @@@@@@? G@@@@@@@@G + B@@@@@@@@5 J&&&B^ ^B&&&J G@@@@@@@@B + P@@@@@@@@G #@@@@@@@@P + ^@@@@@@@@@: ^@@@@@@@@@~ + G@@@@@@@@&. .@@@@@@@@@B + &@@@@@@@@@? #@@@@@@@@&. + .#@@@@@@@@@&Y: ~@@@@@@@&. + Y@@@@@@@@@@@&GY!~^:::: ~^#@@@@@5 + .G@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@B: + .Y&@@@@@@@@@@@@@@@@@@@@@@@@@&Y. + :JB@@@@@@@@@@@@@@@@@@@#J: + :!&@@@@@@@@@@@&!:''') + + print("") + print(Fore.LIGHTBLACK_EX + ''' + █▀▀█ █▀▀█ █▀▀▀█ █▀▀█ █▀▀▀ █▀▀█ + █ █▄▄█ ▀▀▀▄▄ █▄▄█ █▀▀▀ █▄▄▀ + █▄▄█ █ █ █▄▄▄█ █ █▄▄▄ █ █ + DESKTOP ASSISTANT + ''') + print(Fore.YELLOW + " Launching Casper v3.0.0".center(100)) + for i in range(101): + progress(i) + time.sleep(0.01) + + print("") + print(Fore.GREEN + " Systems ready".center(100)) + time.sleep(1) + os.system('cls') \ No newline at end of file diff --git a/open_program.py b/open_program.py new file mode 100644 index 0000000..0016da9 --- /dev/null +++ b/open_program.py @@ -0,0 +1,81 @@ +import os +import colorama +from speech_engine import casper_speak +from colorama import Fore, Back +colorama.init(autoreset=True) + + +def open_program(command, voice_var): + if "chrome" in command.lower(): + print(Fore.GREEN + "Opening Google Chrome".center(100)) + casper_speak(speak="Opening Google Chrome", voice=voice_var) + 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=voice_var) + 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=voice_var) + 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=voice_var) + 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=voice_var) + 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=voice_var) + 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=voice_var) + 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=voice_var) + 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=voice_var) + os.startfile("C:/Users/ashfa/AppData/Roaming/Zoom/bin/Zoom.exe") + return + + elif "activate VPN" in command: + print(Fore.GREEN + "Activating VPN sir".center(100)) + casper_speak(speak="Activating VPN sir", voice=voice_var) + 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=voice_var) + os.startfile("%windir%/system32/taskmgr.exe /7") + return \ No newline at end of file diff --git a/password_manager.py b/password_manager.py new file mode 100644 index 0000000..720fda2 --- /dev/null +++ b/password_manager.py @@ -0,0 +1,179 @@ +import secrets +import string +import pyttsx3 +import os.path +import colorama +from colorama import Fore, Back + +colorama.init(autoreset=True) + +print("Coded by Ashfaaq Rifath") +voice1 = " PASSWORD MANAGER " +print(Fore.BLACK + Back.YELLOW + voice1) +engine = pyttsx3.init() +engine.say(voice1) +engine.runAndWait() +# the pyttsx3 module reads out all the outputs in this program (text to speech) + +# asks the user if they need to generate or add a new password +pass_option = input("Add new or generate password (a/g): ") + + +if pass_option.lower() == "a": + # the desired file path should be added here (hardcoded) + default_path = "G:/My Drive/Password project" + pass_name = input("Name your password: ") + save_path = os.path.join(default_path, pass_name + ".txt") + my_pass = input("Input your password: ") + user_pass = len(my_pass) + if user_pass > 14: + # also contains a password strength meter + voice2 = " Your password is strong " + print(Fore.BLACK + Back.GREEN + voice2) + engine = pyttsx3.init() + engine.say(voice2) + engine.runAndWait() + + elif user_pass < 14: + voice3 = " Password should be stronger " + print(Fore.BLACK + Back.RED + voice3) + engine = pyttsx3.init() + engine.say(voice3) + engine.runAndWait() + + # takes the file path the user wants as an input + choose_loc = input("Save to default location or custom location (d/c): ") + + if choose_loc.lower() == "d": + add_pass = open(save_path, "w") + add_pass.write(f"Saved password for {pass_name}: ") + add_pass.write(my_pass) + add_pass.close() + voice4 = "Password saved" + print(Fore.GREEN + voice4) + engine = pyttsx3.init() + engine.say(voice4) + engine.runAndWait() + + elif choose_loc == "c": + print(Fore.BLACK + Back.YELLOW + " Enter correct file path ") + custom_path = input("Enter file path: ") + save_abs_path = os.path.join(custom_path, pass_name + ".txt") + add_pass = open(save_abs_path, "w") + add_pass.write(f"Saved password for {pass_name}: ") + add_pass.write(my_pass) + add_pass.close() + voice5 = "Password saved" + print(Fore.GREEN + voice5) + engine = pyttsx3.init() + engine.say(voice5) + engine.runAndWait() + + else: + voice6 = " INVALID OPTION " + print(Fore.BLACK + Back.RED + voice6) + engine = pyttsx3.init() + engine.say(voice6) + engine.runAndWait() + +elif pass_option.lower() == "g": + name = input("Name your password: ") + try: + pass_length = int(input("Enter password length: ")) + except: + voice7 = " ENTER VALID NUMBER " + print(Fore.BLACK + Back.RED + voice7) + engine = pyttsx3.init() + engine.say(voice7) + engine.runAndWait() + + special_chars = "!@#$%^&*_~;?<>{}[]" + characters = string.ascii_letters + string.digits + special_chars + + while True: + password = ''.join(secrets.choice(characters) for i in range(pass_length)) + password += secrets.choice(special_chars) + if (any(c.islower() for c in password) and any(c.isupper() + for c in password) and sum(c.isdigit() for c in password) >= 4): + voice8 = f"Password generated for {name}" + print(voice8 , ':', password) + engine = pyttsx3.init() + engine.say(voice8) + engine.runAndWait() + + strength = len(password) + if strength > 14: + voice9 = " Your password is strong " + print(Fore.BLACK + Back.GREEN + voice9) + engine = pyttsx3.init() + engine.say(voice9) + engine.runAndWait() + + elif strength < 14: + voice10 = " Password should be stronger " + print(Fore.BLACK + Back.RED + voice10) + engine = pyttsx3.init() + engine.say(voice10) + engine.runAndWait() + + need_save = input("Do you want to save this password? (y/n): ") + + if need_save.lower() == "y": + choose_loc = input("Save to default location or custom location (d/c): ") + + elif need_save == "n": + print("---------------") + + else: + voice11 = " INVALID OPTION " + print(Fore.BLACK + Back.RED + voice11) + engine = pyttsx3.init() + engine.say(voice11) + engine.runAndWait() + break + + if choose_loc.lower() == "d": + save_path = "G:/My Drive/Password project" + def_path = os.path.join(save_path, name + ".txt") + saving = open(def_path,"w") + saving.write(f"Generated password for {name}: ") + saving.write(password) + saving.close() + voice12 = "Password saved" + print(Fore.GREEN + voice12) + engine = pyttsx3.init() + engine.say(voice12) + engine.runAndWait() + + elif choose_loc.lower() == "c": + voice13 = " Enter correct file path " + print(Fore.BLACK + Back.YELLOW + voice13) + engine = pyttsx3.init() + engine.say(voice13) + engine.runAndWait() + + save_path = input("Enter file path: ") + cus_path = os.path.join(save_path, name + ".txt") + gen_pass = open(cus_path, "w") + gen_pass.write(f"Saved password for {name}: ") + gen_pass.write(password) + gen_pass.close() + voice14 = "Password saved" + print(Fore.GREEN + voice14) + engine = pyttsx3.init() + engine.say(voice14) + engine.runAndWait() + + else: + voice15 = " INVALID OPTION " + print(Fore.BLACK + Back.RED + voice15) + engine = pyttsx3.init() + engine.say(voice15) + engine.runAndWait() + +else: + voice16 = " INVALID OPTION " + print(Fore.BLACK + Back.RED + voice16) + engine = pyttsx3.init() + engine.say(voice16) + engine.runAndWait() \ No newline at end of file diff --git a/recognizer.py b/recognizer.py new file mode 100644 index 0000000..63dceb7 --- /dev/null +++ b/recognizer.py @@ -0,0 +1,30 @@ +import speech_recognition as sr +import sys +import colorama +from colorama import Fore, Back +colorama.init(autoreset=True) + +def casper_listen(): + r = sr.Recognizer() + audio = "" + with sr.Microphone() as source: + # print("") + #print(Fore.YELLOW + "Listening...".center(100)) + audio = r.listen(source, phrase_time_limit=15) + #print(Fore.BLUE + "Processing...".center(100)) + try: + u_said = r.recognize_google(audio, language='en-US') + print(Fore.BLUE + "Processing...".center(100)) + print(f"(●) {u_said}".center(100)) + + print_save = sys.stdout + f = open("Casper Log.txt", 'a', encoding="utf-8") + sys.stdout = f + print(Fore.BLUE + "Processing...".center(100)) + print(f"(●) {u_said}".center(100)) + sys.stdout = print_save + f.close() + return u_said + except: + #print(Fore.LIGHTBLACK_EX + "Awaiting command.".center(100)) + return 0 \ No newline at end of file diff --git a/speech_engine.py b/speech_engine.py new file mode 100644 index 0000000..83f90af --- /dev/null +++ b/speech_engine.py @@ -0,0 +1,9 @@ +import pyttsx3 + +def casper_speak(speak, voice): + engine = pyttsx3.init("sapi5") + engine.setProperty('rate', 150) + voices = engine.getProperty('voices') + engine.setProperty('voice', voices[voice].id) + engine.say(speak) + engine.runAndWait() \ No newline at end of file diff --git a/web_functions.py b/web_functions.py new file mode 100644 index 0000000..39ce8cf --- /dev/null +++ b/web_functions.py @@ -0,0 +1,95 @@ +import webbrowser +import wikipedia +import colorama +from speech_engine import casper_speak +from recognizer import casper_listen +from activity_log import casper_log +from colorama import Fore, Back +colorama.init(autoreset=True) + + +def search_web(command, voice_var): + 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=voice_var) + webbrowser.open(f"http://www.youtube.com/results?search_query={yt_search}") + casper_speak(speak="I found these results", voice=voice_var) + + casper_log(Fore.GREEN + f"Searching YouTube for {yt_search}".center(100)) + casper_log(f"http://www.youtube.com/results?search_query={yt_search}") + casper_log("I found these results") + return + + elif "wikipedia" in command.lower(): + print(Fore.YELLOW + "What do you want to search?".center(100)) + casper_speak(speak="what do you want to search?", voice=voice_var) + + 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=voice_var) + + 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=voice_var) + + casper_log(Fore.YELLOW + "What do you want to search?".center(100)) + casper_log(Fore.GREEN + f"Searching wikipedia for {wiki_search}".center(100)) + casper_log("") + casper_log(Fore.LIGHTBLUE_EX + centr.center(100)) + return + + elif "github" in command or "account" in command.lower(): + print(Fore.GREEN + "Accessing your GitHub account".center(100)) + casper_speak(speak="Accessing your GitHub account", voice=voice_var) + webbrowser.open("https://github.com/ashfaaqrifath") + return + + elif "source code" in command.lower(): + print(Fore.GREEN + "Accessing my source code from GitHub".center(100)) + casper_speak(speak="Accessing my source code from GitHub", voice=voice_var) + 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=voice_var) + 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=voice_var) + webbrowser.open(f"http://www.google.com/search?q={query}") + casper_speak(speak="I found these results", voice=voice_var) + return + + 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=voice_var) + return + + elif "incognito" in command.lower(): + tab = "www.google.com" + chrome_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s --incognito" + webbrowser.get(chrome_path).open_new(tab) + print(Fore.RED + "Enabled Incognito mode".center(100)) + casper_speak(speak="Enabled Incognito mode", voice=voice_var) + return + + elif "where is" in command.lower(): + location = command.replace("where is", "") + google_maps = location + print(Fore.GREEN + f"Locating {google_maps}".center(100)) + casper_speak(speak=f"locating {google_maps}", voice=voice_var) + webbrowser.open(f"https://www.google.nl/maps/place/{location}") + casper_speak(speak=f"{google_maps} Located sir.", voice=voice_var) + return \ No newline at end of file