diff --git a/commentary.py b/commentary.py index 4aec826..7c15479 100644 --- a/commentary.py +++ b/commentary.py @@ -1,3 +1,4 @@ +<<<<<<< HEAD import pyttsx3 #pip install pyttsx3 import speech_recognition as sr #pip install speechRecognition import datetime @@ -156,4 +157,164 @@ def sendEmail(to, content): print(e) speak("Sorry my friend harry bhai. I am not able to send this email") +======= +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") + +>>>>>>> 31bee857ab196b147925431a10b03464e7051e3b \ No newline at end of file diff --git a/debug.log b/debug.log index 3b64032..1b54026 100644 --- a/debug.log +++ b/debug.log @@ -10,6 +10,7 @@ [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 +<<<<<<< HEAD [0120/011342.414: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) [0120/011342.444:ERROR:exception_snapshot_win.cc(98)] thread ID 24884 not found in process [0120/011449.224: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) @@ -20,3 +21,5 @@ [0122/204953.300:ERROR:exception_snapshot_win.cc(98)] thread ID 1792 not found in process [0122/205508.182: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) [0122/205508.185:ERROR:exception_snapshot_win.cc(98)] thread ID 18012 not found in process +======= +>>>>>>> 31bee857ab196b147925431a10b03464e7051e3b diff --git a/pandavoice_assistant.py b/pandavoice_assistant.py index 9d64fa8..ba7d0c1 100644 --- a/pandavoice_assistant.py +++ b/pandavoice_assistant.py @@ -1,3 +1,4 @@ +<<<<<<< HEAD #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 @@ -201,3 +202,207 @@ def sendEmail(to, content): elif 'close' in query.lower(): exit() +======= +#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() + +>>>>>>> 31bee857ab196b147925431a10b03464e7051e3b