Merge branch 'main' into patch-2
This commit is contained in:
commit
7c23f6768b
44
Jarvis2.py
44
Jarvis2.py
@ -12,6 +12,8 @@ import pyttsx3
|
|||||||
import speech_recognition as sr
|
import speech_recognition as sr
|
||||||
import wikipedia
|
import wikipedia
|
||||||
|
|
||||||
|
import gui
|
||||||
|
|
||||||
print("Initializing Jarvis....")
|
print("Initializing Jarvis....")
|
||||||
MASTER = getpass.getuser() or "Harsha"
|
MASTER = getpass.getuser() or "Harsha"
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ def search(search_query, search_engine):
|
|||||||
|
|
||||||
|
|
||||||
def speak(text):
|
def speak(text):
|
||||||
|
gui.speak(text)
|
||||||
engine.say(text)
|
engine.say(text)
|
||||||
engine.runAndWait()
|
engine.runAndWait()
|
||||||
|
|
||||||
@ -58,11 +61,11 @@ def print_and_speak(text):
|
|||||||
def wish_me():
|
def wish_me():
|
||||||
hour = datetime.datetime.now().hour
|
hour = datetime.datetime.now().hour
|
||||||
if hour < 12:
|
if hour < 12:
|
||||||
speak("Good Morning" + MASTER)
|
speak("Good Morning" + master)
|
||||||
elif hour < 18:
|
elif hour < 18:
|
||||||
speak("Good Afternoon" + MASTER)
|
speak("Good Afternoon" + master)
|
||||||
else:
|
else:
|
||||||
speak("Good Evening" + MASTER)
|
speak("Good Evening" + master)
|
||||||
|
|
||||||
# speak("Hey I am Jarvis. How may I help you")
|
# speak("Hey I am Jarvis. How may I help you")
|
||||||
|
|
||||||
@ -95,15 +98,18 @@ def take_command():
|
|||||||
|
|
||||||
speak("Initializing Jarvis....")
|
speak("Initializing Jarvis....")
|
||||||
wish_me()
|
wish_me()
|
||||||
query = take_command().lower()
|
|
||||||
|
|
||||||
# logic for executing basic tasks
|
|
||||||
if "wikipedia" in query.lower():
|
def execute_the_command_said_by_user():
|
||||||
|
query = take_command().lower()
|
||||||
|
|
||||||
|
# logic for executing basic tasks
|
||||||
|
if "wikipedia" in query:
|
||||||
speak("Searching wikipedia....")
|
speak("Searching wikipedia....")
|
||||||
query = query.replace("wikipedia", "")
|
query = query.replace("wikipedia", "")
|
||||||
print_and_speak(wikipedia.summary(query, sentences=2))
|
print_and_speak(wikipedia.summary(query, sentences=2))
|
||||||
|
|
||||||
elif "what's up" in query or "how are you" in query:
|
elif "what's up" in query or "how are you" in query:
|
||||||
st_msgs = (
|
st_msgs = (
|
||||||
"Just doing my thing!",
|
"Just doing my thing!",
|
||||||
"I am fine!",
|
"I am fine!",
|
||||||
@ -112,13 +118,13 @@ elif "what's up" in query or "how are you" in query:
|
|||||||
)
|
)
|
||||||
speak(random.choice(st_msgs))
|
speak(random.choice(st_msgs))
|
||||||
|
|
||||||
elif "date" in query:
|
elif "date" in query:
|
||||||
print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}")
|
print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}")
|
||||||
|
|
||||||
elif "time" in query:
|
elif "time" in query:
|
||||||
print_and_speak(f"{datetime.datetime.now():%I %M %p}")
|
print_and_speak(f"{datetime.datetime.now():%I %M %p}")
|
||||||
|
|
||||||
elif "open" in query.lower():
|
elif "open" in query.lower():
|
||||||
website = query.replace("open", "").strip().lower()
|
website = query.replace("open", "").strip().lower()
|
||||||
try:
|
try:
|
||||||
open_url(popular_websites[website])
|
open_url(popular_websites[website])
|
||||||
@ -126,12 +132,12 @@ elif "open" in query.lower():
|
|||||||
print(f"Unknown website: {website}")
|
print(f"Unknown website: {website}")
|
||||||
speak(f"Sorry, I don't know the website {website}")
|
speak(f"Sorry, I don't know the website {website}")
|
||||||
|
|
||||||
elif "search" in query.lower():
|
elif "search" in query.lower():
|
||||||
search_query = query.split("for")[-1]
|
search_query = query.split("for")[-1]
|
||||||
search_engine = query.split("for")[0].replace("search", "").strip().lower()
|
search_engine = query.split("for")[0].replace("search", "").strip().lower()
|
||||||
search(search_query, search_engine)
|
search(search_query, search_engine)
|
||||||
|
|
||||||
elif "email" in query:
|
elif "email" in query:
|
||||||
speak("Who is the recipient? ")
|
speak("Who is the recipient? ")
|
||||||
recipient = take_command()
|
recipient = take_command()
|
||||||
|
|
||||||
@ -150,19 +156,19 @@ elif "email" in query:
|
|||||||
except Exception:
|
except Exception:
|
||||||
speak("Sorry Sir! I am unable to send your message at this moment!")
|
speak("Sorry Sir! I am unable to send your message at this moment!")
|
||||||
|
|
||||||
elif "nothing" in query or "abort" in query or "stop" in query:
|
elif "nothing" in query or "abort" in query or "stop" in query:
|
||||||
speak("okay")
|
speak("okay")
|
||||||
speak("Bye Sir, have a good day.")
|
speak("Bye Sir, have a good day.")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
elif "hello" in query:
|
elif "hello" in query:
|
||||||
speak("Hello Sir")
|
speak("Hello Sir")
|
||||||
|
|
||||||
elif "bye" in query:
|
elif "bye" in query:
|
||||||
speak("Bye Sir, have a good day.")
|
speak("Bye Sir, have a good day.")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
elif "play music" in query:
|
elif "play music" in query:
|
||||||
music_folder = "Your_music_folder_path(absolute_path)"
|
music_folder = "Your_music_folder_path(absolute_path)"
|
||||||
music = ("music1", "music2", "music3", "music4", "music5")
|
music = ("music1", "music2", "music3", "music4", "music5")
|
||||||
random_music = music_folder + random.choice(music) + ".mp3"
|
random_music = music_folder + random.choice(music) + ".mp3"
|
||||||
@ -170,4 +176,8 @@ elif "play music" in query:
|
|||||||
|
|
||||||
speak("Playing your request")
|
speak("Playing your request")
|
||||||
|
|
||||||
speak("Next Command! Sir!")
|
speak("Next Command! Sir!")
|
||||||
|
|
||||||
|
|
||||||
|
gui.set_speak_command(execute_the_command_said_by_user)
|
||||||
|
gui.mainloop()
|
||||||
|
|||||||
@ -1,174 +1,146 @@
|
|||||||
import datetime
|
import configparser # isort: skip
|
||||||
import random
|
import os # isort: skip
|
||||||
import smtplib
|
|
||||||
import sys
|
|
||||||
import webbrowser
|
|
||||||
|
|
||||||
import pyttsx3
|
import gui # isort: skip
|
||||||
import speech_recognition as sr
|
import speech_recognition as sr # isort: skip
|
||||||
import wikipedia
|
from actions import ( # isort: skip
|
||||||
from pygame import mixer
|
change_rate,
|
||||||
|
change_voice,
|
||||||
|
change_volume,
|
||||||
|
search_engine_selector,
|
||||||
|
set_gui_speak,
|
||||||
|
speak,
|
||||||
|
wish_me
|
||||||
|
)
|
||||||
|
from commands import ( # isort: skip
|
||||||
|
command_bye,
|
||||||
|
command_hello,
|
||||||
|
command_mail,
|
||||||
|
command_nothing,
|
||||||
|
command_open,
|
||||||
|
command_pause_music,
|
||||||
|
command_play_music,
|
||||||
|
command_search,
|
||||||
|
command_stop_music,
|
||||||
|
command_unpause_music,
|
||||||
|
command_whatsup,
|
||||||
|
command_wikipedia
|
||||||
|
)
|
||||||
|
|
||||||
mixer.init()
|
|
||||||
|
|
||||||
print("Initializing Jarvis....")
|
|
||||||
MASTER = "Tony Stark"
|
|
||||||
|
|
||||||
engine = pyttsx3.init("sapi5")
|
|
||||||
voices = engine.getProperty("voices")
|
|
||||||
engine.setProperty("voice", voices[0].id)
|
|
||||||
popular_websites = {
|
popular_websites = {
|
||||||
"google": "https://www.google.com",
|
"google": "https://www.google.com",
|
||||||
"youtube": "https://www.youtube.com",
|
"youtube": "https://www.youtube.com",
|
||||||
"wikipedia": "https://www.wikipedia.org",
|
"wikipedia": "https://www.wikipedia.org",
|
||||||
"amazon": "https://www.amazon.com",
|
"amazon": "https://www.amazon.com",
|
||||||
"GitHub": "https://www.github.com",
|
"github": "https://www.github.com",
|
||||||
}
|
|
||||||
search_engines = {
|
|
||||||
"google": "https://www.google.com",
|
|
||||||
"youtube": "https://www.youtube.com",
|
|
||||||
"bing": "https://www.bing.com",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def open_url(url):
|
def main(search_engine, take_command, debug):
|
||||||
webbrowser.open(url)
|
def execute_the_command_said_by_user():
|
||||||
chrome_path = r"open -a /Applications/Google\ Chrome.app %s"
|
query = take_command()
|
||||||
webbrowser.get(chrome_path).open(url)
|
|
||||||
|
# logic for executing commands without arguments
|
||||||
|
phrases = {
|
||||||
|
"what's up": command_whatsup,
|
||||||
|
"nothing": command_nothing,
|
||||||
|
"abort": command_nothing,
|
||||||
|
"stop": command_nothing,
|
||||||
|
"hello": command_hello,
|
||||||
|
"bye": command_bye,
|
||||||
|
"play music": command_play_music,
|
||||||
|
"unpause": command_unpause_music,
|
||||||
|
"pause music": command_pause_music,
|
||||||
|
"stop music": command_stop_music
|
||||||
|
}
|
||||||
|
for phrase, command in phrases.items():
|
||||||
|
if phrase in query:
|
||||||
|
command()
|
||||||
|
|
||||||
|
# logic for executing commands with arguments
|
||||||
|
if "wikipedia" in query:
|
||||||
|
command_wikipedia(speak, debug, query)
|
||||||
|
|
||||||
|
elif "open" in query:
|
||||||
|
command_open(
|
||||||
|
query,
|
||||||
|
popular_websites,
|
||||||
|
debug,
|
||||||
|
search_engine,
|
||||||
|
take_command
|
||||||
|
)
|
||||||
|
|
||||||
|
elif "search" in query:
|
||||||
|
command_search(query, search_engine)
|
||||||
|
|
||||||
|
elif "mail" in query:
|
||||||
|
command_mail(take_command)
|
||||||
|
|
||||||
|
elif "change rate" in query:
|
||||||
|
change_rate(query, take_command)
|
||||||
|
|
||||||
|
elif "change voice" in query.lower():
|
||||||
|
change_voice(query, take_command)
|
||||||
|
|
||||||
|
elif "change volume" in query.lower():
|
||||||
|
change_volume(query, take_command)
|
||||||
|
|
||||||
|
speak("Next Command! Sir!")
|
||||||
|
gui.set_speak_command(execute_the_command_said_by_user)
|
||||||
|
set_gui_speak(gui.speak)
|
||||||
|
gui.mainloop()
|
||||||
|
|
||||||
|
|
||||||
def search(search_query, search_engine):
|
def run():
|
||||||
try:
|
master = config['DEFAULT']['master']
|
||||||
open_url(f"{search_engines[search_engine]}/search?q={search_query}")
|
|
||||||
except IndexError:
|
|
||||||
open_url(f"https://www.google.com/search?q={search_query}")
|
|
||||||
|
|
||||||
|
search_engine = search_engine_selector(config)
|
||||||
|
|
||||||
def speak(text):
|
debug = config['DEFAULT']['debug']
|
||||||
engine.say(text)
|
|
||||||
engine.runAndWait()
|
|
||||||
|
|
||||||
|
|
||||||
def wish_me():
|
|
||||||
hour = datetime.datetime.now().hour
|
|
||||||
# print(hour)
|
|
||||||
if hour >= 0 and hour < 12:
|
|
||||||
speak("Good Morning" + MASTER)
|
|
||||||
|
|
||||||
elif hour >= 12 and hour < 18:
|
|
||||||
speak("Good Afternoon" + MASTER)
|
|
||||||
|
|
||||||
|
if debug == "True":
|
||||||
|
def take_command():
|
||||||
|
return input("Command |--> ")
|
||||||
else:
|
else:
|
||||||
speak("Good Evening" + MASTER)
|
def take_command():
|
||||||
|
|
||||||
# speak("Hey I am Jarvis. How may I help you")
|
|
||||||
|
|
||||||
|
|
||||||
# This is where our programme begins....
|
|
||||||
def take_command():
|
|
||||||
r = sr.Recognizer()
|
r = sr.Recognizer()
|
||||||
with sr.Microphone() as source:
|
with sr.Microphone() as source:
|
||||||
print("Listening....")
|
print("Listening....")
|
||||||
r.pause_threshold = 0.5
|
r.pause_threshold = 0.5
|
||||||
audio = r.listen(source)
|
audio = r.listen(source)
|
||||||
|
|
||||||
query = ""
|
query = " "
|
||||||
try:
|
try:
|
||||||
print("Recognizing....")
|
print("Recognizing....")
|
||||||
query = r.recognize_google(audio, language="en-in")
|
query = r.recognize_google(audio, language="en-in")
|
||||||
print("user said: " + query)
|
print("user said: " + query)
|
||||||
|
|
||||||
except sr.UnknownValueError:
|
except sr.UnknownValueError:
|
||||||
|
if debug == "True":
|
||||||
print("Sorry Could You please try again")
|
print("Sorry Could You please try again")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
speak("Sorry Could You please try again")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if debug == "True":
|
||||||
print(e)
|
print(e)
|
||||||
print("Say That Again Please")
|
print("Say That Again Please")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
speak(text="Initializing Jarvis....")
|
||||||
|
wish_me(master)
|
||||||
|
main(search_engine, take_command, debug)
|
||||||
|
|
||||||
speak("Initializing Jarvis....")
|
|
||||||
wish_me()
|
|
||||||
while True:
|
|
||||||
query = take_command()
|
|
||||||
|
|
||||||
# logic for executing basic tasks
|
if os.path.isfile('./config.ini'): # Checks if config.ini exists.
|
||||||
if "wikipedia" in query.lower():
|
config = configparser.ConfigParser() # if exists loads library.
|
||||||
speak("Searching wikipedia....")
|
config.read('config.ini') # and also the file.
|
||||||
query = query.replace("wikipedia", "")
|
run() # Then it launches the main program
|
||||||
results = wikipedia.summary(query, sentences=2)
|
else:
|
||||||
print(results)
|
# if it doesn't exist it drops an error message and exits.
|
||||||
speak(results)
|
print('You need a config.ini file.')
|
||||||
|
print('Check the documentation in the Github Repository.')
|
||||||
elif "what's up" in query or "how are you" in query:
|
|
||||||
st_msgs = [
|
|
||||||
"Just doing my thing!",
|
|
||||||
"I am fine!",
|
|
||||||
"Nice!",
|
|
||||||
"I am nice and full of energy",
|
|
||||||
]
|
|
||||||
speak(random.choice(st_msgs))
|
|
||||||
|
|
||||||
elif "open" in query.lower():
|
|
||||||
website = query.replace("open", "").strip().lower()
|
|
||||||
try:
|
|
||||||
open_url(popular_websites[website])
|
|
||||||
except IndexError: # If the website is unknown
|
|
||||||
print(f"Unknown website: {website}")
|
|
||||||
speak(f"Sorry, i don't know the website {website}")
|
|
||||||
|
|
||||||
elif "search" in query.lower():
|
|
||||||
search_query = query.split("for")[-1]
|
|
||||||
search_engine = query.split("for")[0].replace("search", "").strip().lower()
|
|
||||||
search(search_query, search_engine)
|
|
||||||
|
|
||||||
elif "mail" in query:
|
|
||||||
speak("Who is the recipient? ")
|
|
||||||
recipient = take_command()
|
|
||||||
|
|
||||||
if "me" in recipient:
|
|
||||||
try:
|
|
||||||
speak("What should I say? ")
|
|
||||||
content = take_command()
|
|
||||||
|
|
||||||
server = smtplib.SMTP("smtp.gmail.com", 587)
|
|
||||||
server.ehlo()
|
|
||||||
server.starttls()
|
|
||||||
server.login("Your_Username", "Your_Password")
|
|
||||||
server.sendmail("Your_Username", "Recipient_Username", content)
|
|
||||||
server.close()
|
|
||||||
speak("Email sent!")
|
|
||||||
except Exception:
|
|
||||||
speak("Sorry Sir! I am unable to send your message at this moment!")
|
|
||||||
|
|
||||||
elif "nothing" in query or "abort" in query or "stop" in query:
|
|
||||||
speak("okay")
|
|
||||||
speak("Bye Sir, have a good day.")
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
elif "hello" in query:
|
|
||||||
speak("Hello Sir")
|
|
||||||
|
|
||||||
elif "bye" in query:
|
|
||||||
speak("Bye Sir, have a good day.")
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
elif "play music" in query:
|
|
||||||
music_folder = "Your_music_folder_path(absolute_path)"
|
|
||||||
music = ("music1", "music2", "music3", "music4")
|
|
||||||
random_music = music_folder + random.choice(music) + ".mp3"
|
|
||||||
speak("Playing your request")
|
|
||||||
mixer.music.load(random_music)
|
|
||||||
mixer.music.play()
|
|
||||||
|
|
||||||
elif "pause music" in query:
|
|
||||||
mixer.music.pause()
|
|
||||||
|
|
||||||
elif "stop music" in query:
|
|
||||||
mixer.music.stop()
|
|
||||||
|
|
||||||
elif "unpause" in query:
|
|
||||||
mixer.music.unpause()
|
|
||||||
|
|
||||||
speak("Next Command! Sir!")
|
|
||||||
|
|||||||
12
README.md
12
README.md
@ -5,6 +5,17 @@ A Virtual Desktop Assistant Written in Python.
|
|||||||
<img src="https://github.com/Harsha200105/DesktopAssitant/blob/main/resource/JJ.jpeg"> <br>
|
<img src="https://github.com/Harsha200105/DesktopAssitant/blob/main/resource/JJ.jpeg"> <br>
|
||||||
The basic purpose of this is to make work easier as it re-directs you to various main sites and performs various important functions for your PC as well just install it for your system and run it in your code editor or IDE. I will be soon updating it as an application for MacOS, Linux and Windows. Until then you can follow the Contributing Guidelines and Contribute into this Desktop Assistant.<br>
|
The basic purpose of this is to make work easier as it re-directs you to various main sites and performs various important functions for your PC as well just install it for your system and run it in your code editor or IDE. I will be soon updating it as an application for MacOS, Linux and Windows. Until then you can follow the Contributing Guidelines and Contribute into this Desktop Assistant.<br>
|
||||||
|
|
||||||
|
|
||||||
|
Steps to run the Assistant on your pc------------------(use python 3.9)
|
||||||
|
|
||||||
|
Step1. Installing all the necessary python module as mentioned in the requirements.txt file one by one as from the terminal pip install <module_name==version>
|
||||||
|
or
|
||||||
|
Install all the required module all at once by using the command pip install -r requirements.txt
|
||||||
|
|
||||||
|
Step2. For windows user run Jarvis2_4windows.py script.
|
||||||
|
|
||||||
|
Wow All done! Now give the command to jarvis.
|
||||||
|
|
||||||
# Installing :
|
# Installing :
|
||||||
|
|
||||||
- Clone the repo to make it available on your local system by using ```git clone <FORKED_REPO_URL>```
|
- Clone the repo to make it available on your local system by using ```git clone <FORKED_REPO_URL>```
|
||||||
@ -13,6 +24,7 @@ The basic purpose of this is to make work easier as it re-directs you to various
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Contributing Guidelines :<br>
|
# Contributing Guidelines :<br>
|
||||||
- We are Open for Pull Requests
|
- We are Open for Pull Requests
|
||||||
- Please contribute and add value to the code
|
- Please contribute and add value to the code
|
||||||
|
|||||||
BIN
__pycache__/Jarvis2.cpython-37.pyc
Normal file
BIN
__pycache__/Jarvis2.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/Jarvis2_4windows.cpython-37.pyc
Normal file
BIN
__pycache__/Jarvis2_4windows.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/actions.cpython-37.pyc
Normal file
BIN
__pycache__/actions.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/commands.cpython-37.pyc
Normal file
BIN
__pycache__/commands.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/gui.cpython-37.pyc
Normal file
BIN
__pycache__/gui.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/tkscrolledframe.cpython-37.pyc
Normal file
BIN
__pycache__/tkscrolledframe.cpython-37.pyc
Normal file
Binary file not shown.
155
actions.py
Normal file
155
actions.py
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
import configparser
|
||||||
|
import datetime
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
|
import pyttsx3
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def search_engine_selector(config):
|
||||||
|
if config['DEFAULT']['search_engine'] == 'Google':
|
||||||
|
return "https://www.google.com"
|
||||||
|
elif config['DEFAULT']['search_engine'] == 'Bing':
|
||||||
|
return "https://www.bing.com"
|
||||||
|
elif config['DEFAULT']['search_engine'] == 'DuckDuckGo':
|
||||||
|
return "https://www.duckduckgo.com"
|
||||||
|
elif config['DEFAULT']['search_engine'] == 'Youtube':
|
||||||
|
return "https://www.youtube.com"
|
||||||
|
else:
|
||||||
|
# If none of default ones selected triesto fetch https://example.com
|
||||||
|
# to see if its valid as search engine and if its valid it uses it.
|
||||||
|
# If not valid it uses Google.
|
||||||
|
try:
|
||||||
|
if requests.get(
|
||||||
|
f"https://{config['DEFAULT']['search_engine'].lower()}.com",
|
||||||
|
params={'q': 'example'}
|
||||||
|
).status_code == 200:
|
||||||
|
return (
|
||||||
|
f"https://{config['DEFAULT']['search_engine'].lower()}.com"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return "https://www.google.com"
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
return "https://www.google.com"
|
||||||
|
|
||||||
|
|
||||||
|
def open_url(url):
|
||||||
|
webbrowser.open(url)
|
||||||
|
chrome_path = r"open -a /Applications/Google\ Chrome.app %s"
|
||||||
|
webbrowser.get(chrome_path).open(url)
|
||||||
|
|
||||||
|
|
||||||
|
def search(search_query, search_engine):
|
||||||
|
open_url(f"{search_engine}/search?q={search_query}")
|
||||||
|
|
||||||
|
|
||||||
|
def gui_speak(text):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def set_gui_speak(command):
|
||||||
|
global gui_speak
|
||||||
|
gui_speak = command
|
||||||
|
|
||||||
|
|
||||||
|
def speak(text):
|
||||||
|
gui_speak(text)
|
||||||
|
engine.say(text)
|
||||||
|
engine.runAndWait()
|
||||||
|
|
||||||
|
|
||||||
|
def wish_me(master):
|
||||||
|
hour = datetime.datetime.now().hour
|
||||||
|
# print(hour)
|
||||||
|
if hour >= 0 and hour < 12:
|
||||||
|
speak("Good Morning" + master)
|
||||||
|
|
||||||
|
elif hour >= 12 and hour < 18:
|
||||||
|
speak("Good Afternoon" + master)
|
||||||
|
|
||||||
|
else:
|
||||||
|
speak("Good Evening" + master)
|
||||||
|
|
||||||
|
# speak("Hey I am Jarvis. How may I help you")
|
||||||
|
|
||||||
|
|
||||||
|
def change_rate(query, take_command):
|
||||||
|
try:
|
||||||
|
rate = query.split('to')[-1]
|
||||||
|
engine.setProperty('rate', int(rate))
|
||||||
|
speak("¿Do you want to keep this config?")
|
||||||
|
answer = take_command()
|
||||||
|
if answer == "yes":
|
||||||
|
config['DEFAULT']['rate'] = rate
|
||||||
|
with open('config.ini', 'w') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
speak("Invalid value. Please try again.")
|
||||||
|
|
||||||
|
|
||||||
|
def change_voice(query, take_command):
|
||||||
|
try:
|
||||||
|
voice = query.split('to')[-1]
|
||||||
|
if voice == "male":
|
||||||
|
engine.setProperty('voice', voices[0].id)
|
||||||
|
speak("¿Do you want to keep this config?")
|
||||||
|
if take_command() == "yes":
|
||||||
|
config['DEFAULT']['voice'] = 'Male'
|
||||||
|
with open('config.ini', 'w') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
elif voice == "female":
|
||||||
|
engine.setProperty('voice', voices[1].id)
|
||||||
|
speak("¿Do you want to keep this config?")
|
||||||
|
answer = take_command()
|
||||||
|
print(answer)
|
||||||
|
if answer == "yes":
|
||||||
|
config['DEFAULT']['voice'] = 'Female'
|
||||||
|
with open('config.ini', 'w') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
speak("Invalid value. Please try again.")
|
||||||
|
except Exception:
|
||||||
|
speak("Invalid value. Please try again.")
|
||||||
|
|
||||||
|
|
||||||
|
def change_volume(query, take_command):
|
||||||
|
try:
|
||||||
|
volume = query.split('to')[-1]
|
||||||
|
engine.setProperty('volume', int(volume)/100)
|
||||||
|
speak("¿Do you want to keep this config?")
|
||||||
|
answer = take_command()
|
||||||
|
if answer == "yes":
|
||||||
|
config['DEFAULT']['volume'] = volume
|
||||||
|
with open('config.ini', 'w') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
speak("Invalid value. Please try again.")
|
||||||
|
|
||||||
|
|
||||||
|
engine = pyttsx3.init("sapi5")
|
||||||
|
voices = engine.getProperty("voices")
|
||||||
|
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read('config.ini')
|
||||||
|
|
||||||
|
if config['DEFAULT']['voice'] == 'Male':
|
||||||
|
engine.setProperty('voice', voices[0].id)
|
||||||
|
else:
|
||||||
|
engine.setProperty('voice', voices[1].id)
|
||||||
|
|
||||||
|
try:
|
||||||
|
engine.setProperty('rate', int(config['DEFAULT']['rate']))
|
||||||
|
engine.setProperty('volume', int(config['DEFAULT']['volume'])/100)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
speak("Bad config. Setting up default values")
|
||||||
115
commands.py
Normal file
115
commands.py
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import configparser
|
||||||
|
import random
|
||||||
|
import smtplib
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import wikipedia
|
||||||
|
from pygame import mixer
|
||||||
|
|
||||||
|
from actions import open_url, search, speak
|
||||||
|
|
||||||
|
config = configparser.ConfigParser() # if exists loads library.
|
||||||
|
config.read('config.ini')
|
||||||
|
|
||||||
|
|
||||||
|
def command_wikipedia(debug, query):
|
||||||
|
speak("Searching wikipedia....")
|
||||||
|
query = query.replace("wikipedia", "")
|
||||||
|
results = wikipedia.summary(query, sentences=2)
|
||||||
|
if debug == "True":
|
||||||
|
print(results)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
speak(results)
|
||||||
|
|
||||||
|
|
||||||
|
def command_whatsup():
|
||||||
|
st_msgs = [
|
||||||
|
"Just doing my thing!",
|
||||||
|
"I am fine!",
|
||||||
|
"Nice!",
|
||||||
|
"I am nice and full of energy",
|
||||||
|
]
|
||||||
|
speak(random.choice(st_msgs))
|
||||||
|
|
||||||
|
|
||||||
|
def command_open(query, popular_websites, debug, search_engine, take_command):
|
||||||
|
website = query.replace("open", "").strip().lower()
|
||||||
|
try:
|
||||||
|
open_url(popular_websites[website])
|
||||||
|
except KeyError: # If the website is unknown
|
||||||
|
if debug == "True":
|
||||||
|
print(f"Unknown website: {website}")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
speak(f"Sorry, i don't know the website {website}")
|
||||||
|
speak(f"¿Do you want me to search {website} in the web?")
|
||||||
|
if take_command() == "yes":
|
||||||
|
search(website, search_engine)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def command_search(query, search_engine):
|
||||||
|
search_query = query.split("for")[-1]
|
||||||
|
search(search_query, search_engine)
|
||||||
|
|
||||||
|
|
||||||
|
def command_mail(take_command):
|
||||||
|
speak("Who is the recipient? ")
|
||||||
|
recipient = take_command()
|
||||||
|
|
||||||
|
try:
|
||||||
|
speak("What should I say? ")
|
||||||
|
content = take_command()
|
||||||
|
|
||||||
|
email = config['EMAIL']
|
||||||
|
server = smtplib.SMTP(email['server'], email['port'])
|
||||||
|
server.ehlo()
|
||||||
|
server.starttls()
|
||||||
|
server.login(email['username'], email['password'])
|
||||||
|
server.sendmail(email['username'], recipient, content)
|
||||||
|
server.close()
|
||||||
|
speak("Email sent!")
|
||||||
|
except Exception:
|
||||||
|
speak("Sorry Sir!")
|
||||||
|
speak("I am unable to send your message at this moment!")
|
||||||
|
|
||||||
|
|
||||||
|
def command_nothing():
|
||||||
|
speak("okay")
|
||||||
|
speak("Bye Sir, have a good day.")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
def command_hello():
|
||||||
|
speak("Hello Sir")
|
||||||
|
|
||||||
|
|
||||||
|
def command_bye():
|
||||||
|
speak("Bye Sir, have a good day.")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
def command_play_music():
|
||||||
|
try:
|
||||||
|
music_folder = config['DEFAULT']['musicPath']
|
||||||
|
music = ("music1", "music2", "music3", "music4")
|
||||||
|
random_music = music_folder + random.choice(music) + ".mp3"
|
||||||
|
speak("Playing your request")
|
||||||
|
mixer.music.load(random_music)
|
||||||
|
mixer.music.play()
|
||||||
|
except Exception as e:
|
||||||
|
speak(e)
|
||||||
|
|
||||||
|
|
||||||
|
def command_pause_music():
|
||||||
|
mixer.music.pause()
|
||||||
|
|
||||||
|
|
||||||
|
def command_stop_music():
|
||||||
|
mixer.music.stop()
|
||||||
|
|
||||||
|
|
||||||
|
def command_unpause_music():
|
||||||
|
mixer.music.unpause()
|
||||||
15
config.ini
Normal file
15
config.ini
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[DEFAULT]
|
||||||
|
master = YourName
|
||||||
|
search_engine = Google
|
||||||
|
debug = False
|
||||||
|
musicpath =
|
||||||
|
voice = Male
|
||||||
|
rate = 150
|
||||||
|
volume = 100
|
||||||
|
|
||||||
|
[EMAIL]
|
||||||
|
server = smtp.gmail.com
|
||||||
|
port = 587
|
||||||
|
username =
|
||||||
|
password =
|
||||||
|
|
||||||
29
gui.py
Normal file
29
gui.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
main_frame = tk.Frame(master=root)
|
||||||
|
chat_listbox = tk.Listbox(master=main_frame, height=200, width=50)
|
||||||
|
scroll_bar = tk.Scrollbar(master=main_frame)
|
||||||
|
speak_button = tk.Button(master=root, text='Speak', command=lambda: None)
|
||||||
|
|
||||||
|
|
||||||
|
def set_speak_command(command):
|
||||||
|
speak_button.configure(command=command)
|
||||||
|
|
||||||
|
|
||||||
|
speak_button.pack(side=tk.LEFT, anchor=tk.SW)
|
||||||
|
|
||||||
|
|
||||||
|
def speak(text):
|
||||||
|
chat_listbox.insert('end', f'Assistant: {text}')
|
||||||
|
root.geometry('700x500')
|
||||||
|
|
||||||
|
|
||||||
|
chat_listbox.pack(fill=tk.Y, side=tk.LEFT)
|
||||||
|
scroll_bar.pack(side=tk.RIGHT, fill=tk.Y)
|
||||||
|
scroll_bar.configure(command=chat_listbox.yview)
|
||||||
|
chat_listbox.configure(yscrollcommand=scroll_bar.set)
|
||||||
|
main_frame.pack(fill=tk.BOTH)
|
||||||
|
root.wm_title('Desktop assistant')
|
||||||
|
root.resizable(False, False)
|
||||||
|
mainloop = root.mainloop
|
||||||
@ -1,5 +1,10 @@
|
|||||||
|
pygame==2.0.1
|
||||||
|
pyttsx3==2.90
|
||||||
|
SpeechRecognition==3.8.1
|
||||||
|
wikipedia==1.4.0
|
||||||
PyAudio==0.2.11
|
PyAudio==0.2.11
|
||||||
pygame==2.0.1
|
pygame==2.0.1
|
||||||
pyttsx3==2.90
|
pyttsx3==2.90
|
||||||
SpeechRecognition==3.8.1
|
SpeechRecognition==3.8.1
|
||||||
wikipedia==1.4.0
|
wikipedia==1.4.0
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user