Skip to content

Commit

Permalink
Merge pull request #34 from TallGorilla/main
Browse files Browse the repository at this point in the history
Multiple upgrades.
  • Loading branch information
Harsha200105 authored Oct 9, 2021
2 parents 407d3cc + c7e24cf commit acc2d46
Show file tree
Hide file tree
Showing 11 changed files with 403 additions and 184 deletions.
12 changes: 7 additions & 5 deletions Jarvis2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import wikipedia

print("Initializing Jarvis....")
MASTER = getpass.getuser()
master = getpass.getuser()

engine = pyttsx3.init("nsss")
voices = engine.getProperty("voices")
Expand Down Expand Up @@ -58,11 +58,11 @@ def print_and_speak(text):
def wish_me():
hour = datetime.datetime.now().hour
if hour < 12:
speak("Good Morning" + MASTER)
speak("Good Morning" + master)
elif hour < 18:
speak("Good Afternoon" + MASTER)
speak("Good Afternoon" + master)
else:
speak("Good Evening" + MASTER)
speak("Good Evening" + master)

# speak("Hey I am Jarvis. How may I help you")

Expand Down Expand Up @@ -148,7 +148,9 @@ def take_command():
server.close()
speak("Email sent!")
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:
speak("okay")
Expand Down
300 changes: 121 additions & 179 deletions Jarvis2_4windows.py
Original file line number Diff line number Diff line change
@@ -1,200 +1,142 @@
import datetime
import random
import smtplib
import sys
import webbrowser
import configparser
import os

import pyttsx3
import speech_recognition as sr
import wikipedia
from pygame import mixer

mixer.init()

print("Initializing Jarvis....")
MASTER = "Tony Stark"


engine = pyttsx3.init('sapi5') #
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id) #for male voices
# engine.setProperty('voice', voices[1].id) #for female voice

""" RATE"""
rate = engine.getProperty('rate') # getting details of current speaking rate
print ("current voice rate is: ",rate) #printing current voice rate
engine.setProperty('rate',170) # setting up new voice rate
engine.runAndWait()

"""VOLUME"""
volume = engine.getProperty('volume') #getting to know current volume level (min=0 and max=1)
print ("volume level is at : ",volume) #printing current volume level
engine.setProperty('volume',1.0) # setting up volume level between 0 and 1

popular_websites = {'google': 'https://www.google.com',
'youtube': 'https://www.youtube.com',
'wikipedia': 'https://www.wikipedia.org',
'amazon': 'https://www.amazon.com'}
search_engines = {'google': 'https://www.google.com',
'youtube': 'https://www.youtube.com',
'bing': 'https://www.bing.com'}

engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[0].id)

from actions import (
change_rate,
change_voice,
change_volume,
search_engine_selector,
speak,
wish_me,
)
from commands import (
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,
)

popular_websites = {
"google": "https://www.google.com",
"youtube": "https://www.youtube.com",
"wikipedia": "https://www.wikipedia.org",
"amazon": "https://www.amazon.com",
"GitHub": "https://www.github.com",
}
search_engines = {
"google": "https://www.google.com",
"youtube": "https://www.youtube.com",
"bing": "https://www.bing.com",
"github": "https://www.github.com",
}


def main(search_engine, take_command, debug):
while True:
query = take_command()

# 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)

def open_url(url):
webbrowser.open(url)
chrome_path = r"open -a /Applications/Google\ Chrome.app %s"
webbrowser.get(chrome_path).open(url)
elif "change rate" in query:
change_rate(query, take_command)

elif "change voice" in query.lower():
change_voice(query, take_command)

def search(search_query, search_engine):
try:
open_url(f"{search_engines[search_engine]}/search?q={search_query}")
except IndexError:
open_url(f"https://www.google.com/search?q={search_query}")
elif "change volume" in query.lower():
change_volume(query, take_command)

speak("Next Command! Sir!")

def speak(text):
engine.say(text)
engine.runAndWait()

def run():
master = config['DEFAULT']['master']

def wish_me():
hour = datetime.datetime.now().hour
# print(hour)
if hour >= 0 and hour < 12:
speak("Good Morning" + MASTER)
search_engine = search_engine_selector(config)

elif hour >= 12 and hour < 18:
speak("Good Afternoon" + MASTER)
debug = config['DEFAULT']['debug']

if debug == "True":
def take_command():
return input("Command |--> ")
else:
speak("Good Evening" + MASTER)

# speak("Hey I am Jarvis. How may I help you")


# This is where our programme begins....
def take_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening....")
r.pause_threshold = 0.5
audio = r.listen(source)

query = ""
try:
print("Recognizing....")
query = r.recognize_google(audio, language="en-in")
print("user said: " + query)

except sr.UnknownValueError:
print("Sorry Could You please try again")

except Exception as e:
print(e)
print("Say That Again Please")

return query


speak("Initializing Jarvis....")
wish_me()
while True:
query = take_command()

# logic for executing basic tasks
if "wikipedia" in query.lower():
speak("Searching wikipedia....")
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
print(results)
speak(results)

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:
def take_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening....")
r.pause_threshold = 0.5
audio = r.listen(source)

query = " "
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!")
print("Recognizing....")
query = r.recognize_google(audio, language="en-in")
print("user said: " + query)

except sr.UnknownValueError:
if debug == "True":
print("Sorry Could You please try again")
else:
pass
speak("Sorry Could You please try again")

except Exception as e:
if debug == "True":
print(e)
print("Say That Again Please")
else:
pass

return query

speak(text="Initializing Jarvis....")
wish_me(master)
main(search_engine, take_command, debug)


if os.path.isfile('./config.ini'): # Checks if config.ini exists.
config = configparser.ConfigParser() # if exists loads library.
config.read('config.ini') # and also the file.
run() # Then it launches the main program
else:
# if it doesn't exist it drops an error message and exits.
print('You need a config.ini file.')
print('Check the documentation in the Github Repository.')
Binary file added __pycache__/Jarvis2.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/Jarvis2_4windows.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/actions.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/commands.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/gui.cpython-37.pyc
Binary file not shown.
Binary file added __pycache__/tkscrolledframe.cpython-37.pyc
Binary file not shown.
Loading

0 comments on commit acc2d46

Please sign in to comment.