2021-10-06 21:48:16 +02:00
|
|
|
import configparser
|
|
|
|
|
import os
|
2021-10-06 22:12:24 +02:00
|
|
|
|
2021-10-07 17:31:11 +02:00
|
|
|
import speech_recognition as sr
|
2021-10-06 22:12:24 +02:00
|
|
|
from pygame import mixer
|
2021-10-03 15:22:09 +05:30
|
|
|
|
2021-10-07 17:27:42 +02:00
|
|
|
from actions import search_engine_selector, speak, wishMe
|
2021-10-07 17:31:11 +02:00
|
|
|
from commands import (command_bye, command_hello, command_mail,
|
|
|
|
|
command_nothing, command_open, command_pauseMusic,
|
|
|
|
|
command_playMusic, command_search, command_stopMusic,
|
|
|
|
|
command_unpauseMusic, command_whatsup, command_wikipedia)
|
2021-10-03 15:22:09 +05:30
|
|
|
|
2021-10-07 17:27:42 +02:00
|
|
|
mixer.init()
|
2021-10-04 07:56:18 +05:30
|
|
|
|
2021-10-07 16:16:42 +02:00
|
|
|
popular_websites = {
|
|
|
|
|
"google": "https://www.google.com",
|
|
|
|
|
"youtube": "https://www.youtube.com",
|
|
|
|
|
"wikipedia": "https://www.wikipedia.org",
|
|
|
|
|
"amazon": "https://www.amazon.com",
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 22:12:24 +02:00
|
|
|
|
2021-10-07 16:16:42 +02:00
|
|
|
def main(search_engine, takeCommand, debug):
|
2021-10-06 21:48:16 +02:00
|
|
|
while True:
|
|
|
|
|
query = takeCommand()
|
|
|
|
|
|
|
|
|
|
# logic for executing basic tasks
|
|
|
|
|
if "wikipedia" in query.lower():
|
2021-10-07 17:27:42 +02:00
|
|
|
command_wikipedia(
|
|
|
|
|
speak,
|
|
|
|
|
debug,
|
|
|
|
|
query
|
|
|
|
|
)
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "what's up" in query or "how are you" in query:
|
2021-10-07 17:27:42 +02:00
|
|
|
command_whatsup()
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "open" in query.lower():
|
2021-10-07 17:27:42 +02:00
|
|
|
command_open(
|
|
|
|
|
query,
|
|
|
|
|
popular_websites,
|
|
|
|
|
debug,
|
|
|
|
|
search_engine,
|
|
|
|
|
takeCommand
|
|
|
|
|
)
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "search" in query.lower():
|
2021-10-07 17:27:42 +02:00
|
|
|
command_search(query, search_engine)
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "mail" in query:
|
2021-10-07 17:27:42 +02:00
|
|
|
command_mail(takeCommand)
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "nothing" in query or "abort" in query or "stop" in query:
|
2021-10-07 17:27:42 +02:00
|
|
|
command_nothing()
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "hello" in query:
|
2021-10-07 17:27:42 +02:00
|
|
|
command_hello()
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "bye" in query:
|
2021-10-07 17:27:42 +02:00
|
|
|
command_bye()
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "play music" in query:
|
2021-10-07 17:27:42 +02:00
|
|
|
command_playMusic()
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "pause music" in query:
|
2021-10-07 17:27:42 +02:00
|
|
|
command_pauseMusic()
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "stop music" in query:
|
2021-10-07 17:27:42 +02:00
|
|
|
command_stopMusic
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
elif "unpause" in query:
|
2021-10-07 17:27:42 +02:00
|
|
|
command_unpauseMusic()
|
2021-10-06 21:48:16 +02:00
|
|
|
|
|
|
|
|
speak("Next Command! Sir!")
|
|
|
|
|
|
2021-10-07 16:09:11 +02:00
|
|
|
|
2021-10-07 16:16:42 +02:00
|
|
|
def run():
|
|
|
|
|
MASTER = config['DEFAULT']['MASTER']
|
|
|
|
|
|
2021-10-07 17:27:42 +02:00
|
|
|
search_engine = search_engine_selector(config)
|
2021-10-07 16:16:42 +02:00
|
|
|
|
|
|
|
|
debug = config['DEFAULT']['debug']
|
|
|
|
|
|
|
|
|
|
if debug == "True":
|
|
|
|
|
def takeCommand():
|
|
|
|
|
query = input("Command |--> ")
|
|
|
|
|
return query
|
|
|
|
|
else:
|
|
|
|
|
def takeCommand():
|
|
|
|
|
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:
|
|
|
|
|
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
|
|
|
|
|
query = None
|
|
|
|
|
|
|
|
|
|
return query
|
|
|
|
|
|
2021-10-07 17:27:42 +02:00
|
|
|
speak(text="Initializing Jarvis....")
|
2021-10-07 16:16:42 +02:00
|
|
|
wishMe(MASTER)
|
|
|
|
|
main(search_engine, takeCommand, debug)
|
|
|
|
|
|
|
|
|
|
|
2021-10-07 16:09:11 +02:00
|
|
|
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.
|
2021-10-07 16:16:42 +02:00
|
|
|
run() # Then it launches the main program
|
2021-10-07 16:09:11 +02:00
|
|
|
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.')
|