From 31bee857ab196b147925431a10b03464e7051e3b Mon Sep 17 00:00:00 2001 From: sarthak mittal <48448581+mostlypanda@users.noreply.github.com> Date: Sun, 19 Jan 2020 13:20:17 +0530 Subject: [PATCH] Add files via upload --- commentary.py | 159 +++++++++++++++++++++++++++++++ debug.log | 12 +++ pandavoice_assistant.py | 202 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 373 insertions(+) create mode 100644 commentary.py create mode 100644 debug.log create mode 100644 pandavoice_assistant.py diff --git a/commentary.py b/commentary.py new file mode 100644 index 0000000..2255814 --- /dev/null +++ b/commentary.py @@ -0,0 +1,159 @@ +import pyttsx3 #pip install pyttsx3 +import speech_recognition as sr #pip install speechRecognition +import datetime +import wikipedia #pip install wikipedia +import webbrowser +import os +from selenium import webdriver +import smtplib +import time +from pycricbuzz import Cricbuzz +def cricCommentry(): + c = Cricbuzz() + matches = c.matches() + # for match in matches: + match=matches[0] + # print( match) + # if(match['mchstate'] != 'nextlive'): + # print (c.livescore(match['id'])) + # print( c.commentary(match['id'])) + # print( c.scorecard(match['id'])) + print('sun',c.commentary(match['id'])['commentary'][0]['comm']) + a,b=c.commentary(match['id'])['commentary'][0]['comm'],'' + while(1): + if(a!=b): + # speak(a) + d=c.scorecard(match['id'])['scorecard'] + speak(a) + speak(d[0]['batteam']+'score is '+d[0]['runs']+'for'+d[0]['wickets']+'wickets') + b=a + else: + a=c.commentary(match['id'])['commentary'][0]['comm'] + +browser = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe') + +engine = pyttsx3.init('sapi5') +voices = engine.getProperty('voices') +# print(voices[1].id) +engine.setProperty('voice', voices[0].id) + + +def speak(audio): + engine.say(audio) + engine.runAndWait() + + +def wishMe(): + hour = int(datetime.datetime.now().hour) + if hour>=0 and hour<12: + speak("Good Morning!") + + elif hour>=12 and hour<18: + speak("Good Afternoon!") + + else: + speak("Good Evening!") + + speak("Hello Sir. Please tell me how may I help you") + +def takeCommand(): + #It takes microphone input from the user and returns string output + + r = sr.Recognizer() + with sr.Microphone() as source: + print("Listening...") + r.pause_threshold = 1 + audio = r.listen(source) + + try: + print("Recognizing...") + query = r.recognize_google(audio, language='en-in') + print(f"User said: {query}\n") + + except Exception as e: + # print(e) + print("Say that again please...") + return "None" + return query + +def sendEmail(to, content): + server = smtplib.SMTP('smtp.gmail.com', 587) + server.ehlo() + server.starttls() + server.login('youremail@gmail.com', 'your-password') + server.sendmail('youremail@gmail.com', to, content) + server.close() + +if __name__ == "__main__": + wishMe() + while True: + # if 1: + query = takeCommand().lower() + + # Logic for executing tasks based on query + if 'wikipedia' in query: + speak('Searching Wikipedia...') + query = query.replace("wikipedia", "") + results = wikipedia.summary(query, sentences=2) + speak("According to Wikipedia") + print(results) + speak(results) + + elif 'open youtube' in query: + # webbrowser.open("youtube.com") + print("hi") + browser.get('https://www.youtube.com/') + speak("what do you want to search on youtube") + query1 = takeCommand().lower() + search=browser.find_element_by_id('search') + search.send_keys(query1) + sbutton=browser.find_element_by_id('search-icon-legacy') + # browser.find_elements_by_xpath() + sbutton.click() + video=browser.find_elements_by_partial_link_text('') + print(video) + speak('which number you want to listen') + print(video.__len__()) + query2 = takeCommand().lower() + video[19].click() + if(query2=='1'): + video[0].click() + elif 'open google' in query: + webbrowser.open("google.com") + + elif 'open stackoverflow' in query: + webbrowser.open("stackoverflow.com") + + + elif 'play music' in query: + music_dir = 'D:\\Non Critical\\songs\\Favorite Songs2' + songs = os.listdir(music_dir) + print(songs) + os.startfile(os.path.join(music_dir, songs[0])) + + elif 'the time' in query: + strTime = datetime.datetime.now().strftime("%H:%M:%S") + speak(f"Sir, the time is {strTime}") + + elif 'open code' in query: + codePath = "C:\\Users\\Haris\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe" + os.startfile(codePath) + + elif 'email to me' in query: + try: + speak("What should I say?") + content = takeCommand() + to = "sarthakmittal1461@gmail.com" + sendEmail(to, content) + speak("Email has been sent!") + except Exception as e: + print(e) + speak("Sorry my friend . I am not able to send this email") + elif 'commentary' in query.lower(): + try: + cricCommentry() + except Exception as e: + print(e) + speak("Sorry my friend harry bhai. I am not able to send this email") + + \ No newline at end of file diff --git a/debug.log b/debug.log new file mode 100644 index 0000000..baa27c5 --- /dev/null +++ b/debug.log @@ -0,0 +1,12 @@ +[0118/220701.479:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022) +[0118/220701.497:ERROR:exception_snapshot_win.cc(98)] thread ID 28616 not found in process +[0118/221118.268:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022) +[0118/221118.269:ERROR:exception_snapshot_win.cc(98)] thread ID 28120 not found in process +[0118/231558.669:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022) +[0118/231558.840:ERROR:exception_snapshot_win.cc(98)] thread ID 10576 not found in process +[0118/231844.970:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022) +[0118/231844.971:ERROR:exception_snapshot_win.cc(98)] thread ID 9084 not found in process +[0118/232842.771:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022) +[0118/232842.772:ERROR:exception_snapshot_win.cc(98)] thread ID 16960 not found in process +[0119/105837.067:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022) +[0119/105837.662:ERROR:exception_snapshot_win.cc(98)] thread ID 14660 not found in process diff --git a/pandavoice_assistant.py b/pandavoice_assistant.py new file mode 100644 index 0000000..c6453e0 --- /dev/null +++ b/pandavoice_assistant.py @@ -0,0 +1,202 @@ +#coden for direct play of any music on youtube search anything on youtube and also for date time and email too + +import pyttsx3 #pip install pyttsx3 +import speech_recognition as sr #pip install speechRecognition +import datetime +import wikipedia #pip install wikipedia +import webbrowser +import os +from selenium import webdriver +import smtplib +import time +import urllib.request +import urllib.parse +import re + +browser = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe') + +engine = pyttsx3.init('sapi5') +voices = engine.getProperty('voices') +# print(voices[1].id) +engine.setProperty('voice', voices[0].id) + + +def speak(audio): + engine.say(audio) + engine.runAndWait() + + +def wishMe(): + hour = int(datetime.datetime.now().hour) + if hour>=0 and hour<12: + speak("Good Morning!") + + elif hour>=12 and hour<18: + speak("Good Afternoon!") + + else: + speak("Good Evening!") + + speak("Hello Sir. Please tell me how may I help you") + +def takeCommand(): + #It takes microphone input from the user and returns string output + + r = sr.Recognizer() + with sr.Microphone() as source: + print("Listening...") + r.pause_threshold = 1 + audio = r.listen(source) + + try: + print("Recognizing...") + query = r.recognize_google(audio, language='en-in') + print(f"User said: {query}\n") + + except Exception as e: + # print(e) + print("Say that again please...") + return "None" + return query + +def sendEmail(to, content): + server = smtplib.SMTP('smtp.gmail.com', 587) + server.ehlo() + server.starttls() + server.login('youremail@gmail.com', 'your-password') + server.sendmail('youremail@gmail.com', to, content) + server.close() + +if __name__ == "__main__": + wishMe() + while True: + # if 1: + query = takeCommand().lower() + + # Logic for executing tasks based on query + if 'wikipedia' in query: + speak('Searching Wikipedia...') + query = query.replace("wikipedia", "") + results = wikipedia.summary(query, sentences=2) + speak("According to Wikipedia") + print(results) + speak(results) + + elif 'open youtube' in query: + # webbrowser.open("http://www.youtube.com/") + print("hi") + #browser.get('https://www.youtube.com/') + speak("what do you want to search on youtube") + r = sr.Recognizer() + with sr.Microphone() as source: + audio = r.listen(source) + + # get the text from audio + msg = r.recognize_google(audio) + + # song name from user + song = urllib.parse.urlencode({"search_query" : msg}) + print(song) + + + # fetch the ?v=query_string + result = urllib.request.urlopen("http://www.youtube.com/results?" + song) + print(result) + + + # make the url of the first result song + search_results = re.findall(r'href=\"\/watch\?v=(.{11})', result.read().decode()) + print(search_results) + + # make the final url of song selects the very first result from youtube result + url = "http://www.youtube.com/watch?v="+search_results[0] + + # play the song using webBrowser module which opens the browser + # webbrowser.open(url, new = 1) + webbrowser.open_new(url) + + + #query1 = takeCommand().lower() + #search=browser.find_element_by_id('search') + #search.send_keys(query1) + #sbutton=browser.find_element_by_id('search-icon-legacy') + # browser.find_elements_by_xpath() + #sbutton.click() + #video=browser.find_elements_by_partial_link_text('') + #print(video) + #speak('which number you want to listen') + #print(video.__len__()) + #query2 = takeCommand().lower() + #video[19].click() + #if(query2=='1'): + # video[0].click() + elif 'open google' in query: + webbrowser.open("google.com") + + elif 'open stackoverflow' in query: + webbrowser.open("stackoverflow.com") + + + elif 'play music' in query: + music_dir = 'D:\\Non Critical\\songs\\Favorite Songs2' + songs = os.listdir(music_dir) + print(songs) + os.startfile(os.path.join(music_dir, songs[0])) + + elif 'the time' in query: + strTime = datetime.datetime.now().strftime("%H:%M:%S") + speak(f"Sir, the time is {strTime}") + + elif 'open code' in query: + codePath = "C:\\Users\\Haris\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe" + os.startfile(codePath) + + elif 'email to mohinesh' in query: + try: + speak("What should I say?") + content = takeCommand() + to ="mohinrshsharma9999@gmail.com" + sendEmail(to, content) + speak("Email has been sent!") + except Exception as e: + print(e) + speak("Sorry my friend harry bhai. I am not able to send this email") + + elif 'make me happy' in query: + speak(" sarthak aayu, you are so beautiful") + + + elif 'play some music' in query: + r = sr.Recognizer() + with sr.Microphone() as source: + speak("which song you wanna listen:") + audio = r.listen(source) + + # get the text from audio + msg = r.recognize_google(audio) + + # song name from user + song = urllib.parse.urlencode({"search_query" : msg}) + print(song) + + + # fetch the ?v=query_string + result = urllib.request.urlopen("http://www.youtube.com/results?" + song) + print(result) + + + # make the url of the first result song + search_results = re.findall(r'href=\"\/watch\?v=(.{11})', result.read().decode()) + print(search_results) + + # make the final url of song selects the very first result from youtube result + url = "http://www.youtube.com/watch?v="+search_results[0] + + # play the song using webBrowser module which opens the browser + # webbrowser.open(url, new = 1) + webbrowser.open_new(url) + + + elif 'close' in query.lower(): + exit() +