diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..665f5ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.mov +*.idea/ +*.DS_Store +_pycache__/q \ No newline at end of file diff --git a/Problem Statement 1/assist.gif b/Problem Statement 1/assist.gif new file mode 100644 index 0000000..be552df Binary files /dev/null and b/Problem Statement 1/assist.gif differ diff --git a/Problem Statement 1/constants.py b/Problem Statement 1/constants.py new file mode 100644 index 0000000..6e4df12 --- /dev/null +++ b/Problem Statement 1/constants.py @@ -0,0 +1,10 @@ +WIKIPEDIA_URL='https://en.wikipedia.org/wiki/' +STACKOVERFLOW_URL = 'stackoverflow.com' +GOOGLE_SEARCH_URL='https://google.com/search?q=' +YOUTUBE_URL='https://www.youtube.com/' +GOOGLE_URL='https://www.google.com/' +GMAIL_URL='https://mail.google.com/' +GOOGLE_MAP_URL='https://google.nl/maps/place/' +JOKE_URL="https://sv443.net/jokeapi/v2/joke/Programming,Miscellaneous,Pun?blacklistFlags=nsfw,religious,political,racist,sexist" +COVID_URL='https://api.covid19api.com/country/india/status/confirmed/live' +NEWS_URL='http://newsapi.org/v2/top-headlines?sources=the-times-of-india&apiKey=ae5ccbe2006a4debbe6424d7e4b569ec' diff --git a/Problem Statement 1/main.py b/Problem Statement 1/main.py new file mode 100644 index 0000000..8725cca --- /dev/null +++ b/Problem Statement 1/main.py @@ -0,0 +1,284 @@ +import speech_recognition as sr +import webbrowser +from constants import WIKIPEDIA_URL, GOOGLE_SEARCH_URL, STACKOVERFLOW_URL, YOUTUBE_URL, GOOGLE_URL, GMAIL_URL,\ + GOOGLE_MAP_URL, JOKE_URL, COVID_URL +import json +import requests +import tkinter +from tkinter import * +import random +import os +from gtts import gTTS +import playsound +from time import ctime +import datetime +from utils import DesktopAssistant + +obj = DesktopAssistant() +r = sr.Recognizer() + + +def is_present(terms, voice_data): + for term in terms: + if term in voice_data: + return True + + +def speak(audio_string): + tts = gTTS(text=audio_string, lang='en-in') + r = random.randint(1, 20000000) + audio_file = 'audio-' + str(r) + '.mp3' + tts.save(audio_file) + playsound.playsound(audio_file) + print(audio_string) + os.remove(audio_file) + + +def record_audio(ask=False): + with sr.Microphone() as source: + r.energy_threshold = 500 # voice level number increase more sensitive + r.adjust_for_ambient_noise(source, 1.2) # noise cancel rate + r.pause_threshold = 1 + r.energy_threshold = 400 + if ask: + speak(ask) + audio = r.listen(source) + voice_data = '' + + try: + voice_data = r.recognize_google(audio, language='en-in') + + except sr.RequestError: + speak('Sorry, the service is down') + except sr.UnknownValueError: + print('Recognizing..') + print(f">> {voice_data.lower()}") + return voice_data.lower() + + +def wishMe(start): + hour = int(datetime.datetime.now().hour) + if start == True: + if hour>=0 and hour<12: + speak("Good Morning!") + + elif hour>=12 and hour<16: + speak("Good Afternoon!") + elif hour>=16 and hour<20: + speak("Good Evening!") + else: + speak("Good Night!") + c_time = obj.tell_time() + speak("Initializing WAVE") + speak("Starting all systems applications") + speak(f"Currently it is {c_time}") + speak("I am Wave. Your desktop assistant. Good to see you again.") + else: + speak('Goodbye sir') + if hour>=0 and hour<12: + speak("Have a good day!") + + elif hour>=18 and hour<24: + speak("Have a good night!") + pass + +def callAssistant(): + wishMe(True) + while True: + voice_data = record_audio() + if is_present(["hey", "hi", "hello", "wake up", "hai","hay"], voice_data): + greetings = ["hey", "hey, what's up? ", " how can I help you", "I'm listening", "hello"] + greet = greetings[random.randint(0, len(greetings) - 1)] + speak(greet) + + + if is_present(["your name", "what i call you", "what is your good name"], voice_data): + name = record_audio("my name is Wave stand for virtual assistance version One. what's your name?") + speak('Nice to meet you ' + name) + speak('how can i help you ' + name) + + + if is_present(["who are you", "your inventor", "invented you", "created you", "who is your developer"], + voice_data): + greetings = ["I am Virtual Voice Assistant", + "I am developed by sayali as a voice assistance"] # You can Add your name + greet = greetings[random.randint(0, len(greetings) - 1)] + speak(greet) + + if is_present(["what is your age", "how old are you", "when is your birthday"], + voice_data): + greetings = ["I came into this world in June 2022"] + greet = greetings[random.randint(0, len(greetings) - 1)] + speak(greet) + + + if is_present( + ["how's everything", "how ia everything", "how are you", "how are you doing", "what's up", "whatsup"], + voice_data): + greetings = ["I am well ...thanks for asking ", "i am well", "Doing Great"] + greet = greetings[random.randint(0, len(greetings) - 1)] + speak(greet) + + + if is_present(["What are you doing", "what you doing", "doing"], voice_data): + greetings = ["nothing", "nothing...,just working for you", "Nothing much"] + greet = greetings[random.randint(0, len(greetings) - 1)] + speak(greet) + + + if is_present( + ["what's the time", "tell me the time", "what time is it", "what is the time", "time is going on"], + voice_data): + time = ctime().split(" ")[3].split(":")[0:2] + if time[0] == "00": + hours = '12' + else: + hours = time[0] + minutes = time[1] + time = f'{hours} {minutes}' + speak(time) + + + if is_present(["wikipedia"],voice_data): + search = record_audio('What do you want to search for?') + url = WIKIPEDIA_URL + search + webbrowser.get().open(url) + speak('Here is what I found for' + search) + + + if is_present(["do google", "search google", "on google", "search for", "in google", "open google search"], + voice_data): + search = record_audio('What do you want to search for?') + url = GOOGLE_SEARCH_URL + search + webbrowser.get().open(url) + speak('Here is what I found for' + search) + + elif is_present(["open stackoverflow"], voice_data): + try: + webbrowser.open(STACKOVERFLOW_URL) + speak('Opening') + except: + speak('Could not perform the task. Please try again.') + + + if is_present(["open the youtube", "open youtube"], voice_data): + webbrowser.get().open(YOUTUBE_URL) + speak('Opening') + + + if is_present(["open the google", "open google"], voice_data): + webbrowser.get().open(GOOGLE_URL) + speak('Opening') + + + if is_present(["open gmail", "open email", "open my email", "check email"], voice_data): + + webbrowser.get().open(GMAIL_URL) + speak('Opening') + + + if is_present(["search youtube", "search the youtube", "search in youtube", "in youtube", "on youtube", "youtube" + "youtube search"],voice_data): + search = record_audio('What do you want to search for?') + r.pause_threshold = 2 + url = YOUTUBE_URL + 'results?search_query=' + search + webbrowser.get().open(url) + speak('Here is what I found') + + if is_present(["location"], voice_data): + location = record_audio('What is the location?') + url = GOOGLE_MAP_URL + location + '/&' + webbrowser.get().open(url) + speak('Opening map of' + location) + + # OS shutdown + if is_present(["shutdown system", "system off", "shutdown the system", "system shutdown"], voice_data): + speak('Okay system will off in 30 seconds') + os.system("shutdown /s /t 30") + + if is_present(["good", "thank you", "thanks", "well done"], voice_data): + greetings = ["my pleasure", "Don't mention", "Thanks for your compliment", "No problem.", + "Thank you, it makes my day to hear that."] + greet = greetings[random.randint(0, len(greetings) - 1)] + speak(greet) + + if is_present(["exit", "quit", "sleep", "shut up", "close"], voice_data): + greetings = ["Going offline ! you can call me Anytime", "Okay ,you can call me Anytime", "See you later", + "See you soon", "Have a good day."] + greet = greetings[random.randint(0, len(greetings) - 1)] + speak(greet) + exit() + + if is_present(['love'], voice_data): + speak('Wave loves you too') + + + if is_present(['joke'], voice_data): + speak("Fetching one...") + data = requests.get(JOKE_URL).text + parse = json.loads(data) + if parse['type'] == 'single': + speak(f"{parse['joke']}") + else: + speak(f"{parse['setup']}") + speak(f"{parse['delivery']}") + + elif is_present(['corona cases', 'covid cases'], voice_data): + data = requests.get(COVID_URL).text + parser = json.loads(data) + l = parser[::-1] + today = (l[0]) + speak(f"There are {today['Cases']} confirmed corona cases in India.") + + elif is_present(['system'], voice_data): + sys_info = obj.system_info() + print(sys_info) + speak(sys_info) + elif is_present(['buzzing', 'news', 'headlines'], voice_data): + news_res = obj.news() + speak('Source: The Times Of India') + speak('Todays Headlines are..') + for index, articles in enumerate(news_res): + speak(articles['title']) + if index == len(news_res) - 2: + break + speak('These were the top headlines, Have a nice day!!..') + + +def update(ind): + frame = frames[(ind)%100] + ind += 1 + label.configure(image=frame) + wn.after(100, update, ind) + +# Creating the main window + +wn = tkinter.Tk() +label1 = Label(wn, text = 'Wave Your Desktop Assistant', bg = 'black') +label1.config(font=("Comic Sans MS", 20)) +label1.pack() + +frames = [PhotoImage(file='assist.gif',format = 'gif -index %i' %(i)) for i in range(100)] +wn.title("Wave Desktop Assistant") + +wn.geometry('700x300') +wn.config(bg='LightBlue1') +label = Label(wn, width = 500, height = 500) +label.pack() +wn.after(0, update, 0) + +btn_call = Button(text = 'Start',width = 20, command = callAssistant, bg = '#5C85FB') +btn_call.config(font=("Courier", 15)) +btn_call.pack() + +btn_exit = Button(text = 'EXIT',width = 20, command = wn.destroy, bg = '#5C85FB') +btn_exit.config(font=("Courier", 15)) +btn_exit.pack() + +showCommand = StringVar() +cmdLabel = Label(wn, textvariable=showCommand, bg='LightBlue1', + fg='black', font=('Courier', 20)) +cmdLabel.place(x=250, y=150) + +# Runs the window till it is closed +wn.mainloop() \ No newline at end of file diff --git a/Problem Statement 1/requirements.txt b/Problem Statement 1/requirements.txt new file mode 100644 index 0000000..5621969 --- /dev/null +++ b/Problem Statement 1/requirements.txt @@ -0,0 +1,4 @@ +SpeechRecognition==3.8.1 +wikipedia==1.4.0 +gTTS==2.2.4 +playsound==1.3.0 diff --git a/Problem Statement 1/utils.py b/Problem Statement 1/utils.py new file mode 100644 index 0000000..f8082c5 --- /dev/null +++ b/Problem Statement 1/utils.py @@ -0,0 +1,18 @@ +from features import date_time, news, sys_stat + +class DesktopAssistant: + def __init__(self): + pass + + def tell_time(self): + return date_time.time() + + def system_info(self): + return sys_stat.system_stats() + + def news(self): + """ + Fetch top news of the day from google news + :return: news list of string if True, False if fail + """ + return news.get_news() \ No newline at end of file diff --git a/Problem Statement 2/README.md b/Problem Statement 2/README.md deleted file mode 100644 index baf2489..0000000 --- a/Problem Statement 2/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Problem Statement-2. - - -*** -### Make a Simple Image Editing app - - - -*** - diff --git a/Problem Statement 3/README.md b/Problem Statement 3/README.md deleted file mode 100644 index b4683b3..0000000 --- a/Problem Statement 3/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Problem Statement-3. - - -*** -### Make a calculator with GUI - - - -*** - diff --git a/README.md b/README.md index dd00367..2b49524 100644 --- a/README.md +++ b/README.md @@ -1,66 +1,23 @@ -# GAME OF CODES +# Wave - Desktop Assistant +A context-aware GUI desktop assistant named as "Ruby" using python and python-tkinter +# Prerequisites -# How to Register in GAME OF CODES +You must have SpeechRecognition, gTTS, playsound and wikipedia installed. -#### Step1: Register yourself in our website +Install requirements using : pip install -r requirements.txt -[Hack2skill Website](https://hack2skill.com/hack/goc3) +#Running the project +Ensure that you are in the project home directory. Start the Desktop assistant by running below command - -#### Step2: Join our discord server +``python main.py `` -[Hack2skill Discord Server](https://discord.gg/2acmdTsKeR) +If everything goes well, you should be able to see the tkinter window as below. +![Screenshot](screenshot.png) -#### Step3: Follow our github organization +#Watch Demo +Watch Wave - Desktop Assistant +Click the start button to initiate interaction and there you go. -[Hack2skill GitHub Organization](https://github.com/hack2skill) - -#### Step4: Read the guidelines -*** - -## Guidelines for the participants: - -1. Participant should register for the competition in our website. -2. Should join our discord server. -3. Participants can participate individually only. -4. Please refrain from discussing strategy during the contest. -5. Do not share your code during the contest. -6. Plagiarism of any means will lead to disqualification. -7. All submissions will run through a plagiarism detector before deciding the winners.Any case of code plagiarism will disqualify both users from the contest & their scores would be set to null for the particular contest. -8. The decisions of the panel will be final and binding in all forms. - -#### Step5: Read the Score Criteria : - - -### Important Note: - -Primary Shortlisting would be based on the video, hence try to make the video of good quality. - -## Score Criteria: - -Scores are given out of 100 based on : - -Creativity of the Project (10 points)
-Unique Selling Point (10 points)
-Solving the Problem Statement (10 points)
-Presentation Skills - eg. Video (10 points)
-Applying GUI - eg. Browser using Django/Flask or Tkinter (10 points )
- - -*** - - -#### Step6: Be active in our discord server - -# Project Submission: -#### Step7: Compete with others by making a PR in our repository - -Participants have to make a video (screen recording) of the workings of their project. - -They need to upload the project code to the Github.
-Step 7.1: Fork the main repository
-Step 7.2: Delete the problem statement folders you are not working on
-Step 7.3: Upload the video of its working in the main folder and files in the problem statement folder
-Step 7.4: Send pull request to the repository
-*** +Note : Also remember to have a fast and secured internet connection to make this run. Because it is using google speech recognition api to understand the commands. \ No newline at end of file diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..81c4a3e Binary files /dev/null and b/screenshot.png differ