From 8c130fb810bb1981a602d3b6370733f5be68fb00 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 15 Jun 2016 14:36:37 -0700 Subject: [PATCH 1/7] initial commit --- speech.py | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 speech.py diff --git a/speech.py b/speech.py new file mode 100644 index 0000000..4787875 --- /dev/null +++ b/speech.py @@ -0,0 +1,201 @@ +import smtplib +import speech_recognition +import pyttsx +from random import randint +import time +#printer stuff +import tempfile +import win32api +import win32print + +speech_engine = pyttsx.init('sapi5') # see http://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init +speech_engine.setProperty('rate', 150) + +contact_dict = {"MATTHEW":"matthew.hope16@ycdsbk12.ca", "MATT": "matt-hope@hotmail.com", + "ANDREW": "andrewhope772@gmail.com"} + +user_dict = {"MATTHEW":"matthew.hope16@ycdsbk12.ca" ,"ANDREW": "andrewhope772@gmail.com"} + +pass_dict = {"MATTHEW":"Mh1097465", "ANDREW": "temp"} + +def speak(text): + """ + + :rtype: object + """ + + speech_engine.say(text) + speech_engine.runAndWait() + + +recognizer = speech_recognition.Recognizer() + + +def listen(): + + with speech_recognition.Microphone() as source: + recognizer.adjust_for_ambient_noise(source) + audio = recognizer.listen(source) + + try: + return recognizer.recognize_google(audio) + + except speech_recognition.UnknownValueError: + print("Could not understand audio") + speak("could not understand audio") + speak("Im listening again") + listen() + except speech_recognition.RequestError as e: + print("Recog Error; {0}".format(e)) + + return "" + +def user_prompt(): + + prompt = False + + while prompt == False: + + usage_list = ["EMAIL","PRINTER","JOKE"] + print "what would you like to do? Email,? Check printer?" + speak("what would you like to do?") + user_res = listen().upper() + print user_res + + if "EMAIL" in user_res: + email_prompt() + prompt = True + + elif "JOKE" in user_res: + joke() + prompt = True + + elif "TIME" in user_res or "DATE" in user_res: + date_time() + prompt = True + + elif "PRINT" in user_res: + send_to_printer() + prompt = True + + + else: + print "invalid command" + prompt = False + + +def email_prompt(): + + print "do you want to send an email" + speak("do you want to send an email? ") + ans = listen() + print ans + + if ans == "yes": + print ans + print "get ready to email:" + speak("get ready to email") + send_email() + else: + + print ans + print "okay, no email then" + speak("okay, no email then") + user_prompt() + +def send_email(): + + server = smtplib.SMTP('smtp.gmail.com', 587) + server.starttls() + + user_valid = False + + while user_valid == False: + + speak("what is your username ") + print "what is your username " + user = listen().upper() + print user + + if user in contact_dict: + user_valid = True + + else: + user_valid = False + + + + server.login(user_dict[user],pass_dict[user]) # logs into the gmail server + + speak("who do you want to send this to") + send_to = listen().upper() + print send_to +# you need a while loop here + if send_to in contact_dict: + + speak("what do you want to say to" + contact_dict[send_to]) + msg = listen() + print msg + server.sendmail(user_dict[user], contact_dict[send_to], msg) + print "email sent" + + else: + print "that name is not in your contacts " + + server.quit() + user_prompt() + +def joke(): + joke_num = randint(1,3) + + if joke_num == 1: + print"why are there fences in a grave yard? because people were dying to get in " + speak("why are there fences in a grave yard?.. because people are dying to get in") + + elif joke_num == 2: + print "how did the frog die? he kermit suicide" + speak("how did the frog die?... he kermit suicide ") + + elif joke_num == 3: + print "I sold my vacuum the other day, all it was doing was collecting dust " + speak("I sold my vacuum the other day... all it was doing was collecting dust") + +#user_prompt() +# tells user 1 of three random jokes + +def date_time(): + + localtime = time.asctime(time.localtime(time.time())) + print "the current time is: ", localtime + speak("the current time is" + localtime) + user_prompt() + #tells user the date and time +def send_to_printer(): + + print "what do you want to print" + speak("what do you want to print") + ans = listen() + print ans + + filename = tempfile.mktemp (".txt") + open (filename, "w").write (ans) + win32api.ShellExecute ( + 0, + "print", + filename, + # + # If this is None, the default printer will + # be used anyway. + # + '/d:"%s"' % win32print.GetDefaultPrinter (), + ".", + 0 + ) + + # sends something to default printer + print "sent",ans,"to printer" + +def main(): + user_prompt() + +main() From afc801fddfcdbc0d32f74f4ea571869c37628065 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 15 Jun 2016 18:41:59 -0700 Subject: [PATCH 2/7] added docstrings --- speech.py | 111 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 82 insertions(+), 29 deletions(-) diff --git a/speech.py b/speech.py index 4787875..36a4ed9 100644 --- a/speech.py +++ b/speech.py @@ -3,7 +3,7 @@ import pyttsx from random import randint import time -#printer stuff +# printer stuff import tempfile import win32api import win32print @@ -11,19 +11,20 @@ speech_engine = pyttsx.init('sapi5') # see http://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init speech_engine.setProperty('rate', 150) -contact_dict = {"MATTHEW":"matthew.hope16@ycdsbk12.ca", "MATT": "matt-hope@hotmail.com", +contact_dict = {"MATTHEW": "matthew.hope16@ycdsbk12.ca", "MATT": "matt-hope@hotmail.com", "ANDREW": "andrewhope772@gmail.com"} -user_dict = {"MATTHEW":"matthew.hope16@ycdsbk12.ca" ,"ANDREW": "andrewhope772@gmail.com"} +user_dict = {"MATTHEW": "matthew.hope16@ycdsbk12.ca", "ANDREW": "andrewhope772@gmail.com"} + +pass_dict = {"MATTHEW": "Mh1097465", "ANDREW": "temp"} -pass_dict = {"MATTHEW":"Mh1097465", "ANDREW": "temp"} def speak(text): """ - - :rtype: object + :param text: string : text that the computer will say to the user + :return: None """ - + speech_engine.say(text) speech_engine.runAndWait() @@ -32,6 +33,10 @@ def speak(text): def listen(): + """ + listens for user input + :return: the user input as a string + """ with speech_recognition.Microphone() as source: recognizer.adjust_for_ambient_noise(source) @@ -50,13 +55,18 @@ def listen(): return "" + def user_prompt(): + """ + asks user what they would like the computer to do + :return: None + """ prompt = False while prompt == False: - usage_list = ["EMAIL","PRINTER","JOKE"] + usage_list = ["EMAIL", "PRINTER", "JOKE"] print "what would you like to do? Email,? Check printer?" speak("what would you like to do?") user_res = listen().upper() @@ -78,6 +88,11 @@ def user_prompt(): send_to_printer() prompt = True + elif "HELP" in user_res: + user_help() + prompt = True + + else: print "invalid command" @@ -85,6 +100,10 @@ def user_prompt(): def email_prompt(): + """ + prompts user for if they want to send email + :return: None + """ print "do you want to send an email" speak("do you want to send an email? ") @@ -103,7 +122,12 @@ def email_prompt(): speak("okay, no email then") user_prompt() + def send_email(): + """ + connects to gmail server, sends email from users address to one of their contacts + :return: None + """ server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() @@ -123,14 +147,12 @@ def send_email(): else: user_valid = False - - - server.login(user_dict[user],pass_dict[user]) # logs into the gmail server + server.login(user_dict[user], pass_dict[user]) # logs into the gmail server speak("who do you want to send this to") send_to = listen().upper() print send_to -# you need a while loop here + # you need a while loop here if send_to in contact_dict: speak("what do you want to say to" + contact_dict[send_to]) @@ -145,8 +167,13 @@ def send_email(): server.quit() user_prompt() + def joke(): - joke_num = randint(1,3) + """ + ramdomly picks one of three different jokes and tells to user + :return: None + """ + joke_num = randint(1, 3) if joke_num == 1: print"why are there fences in a grave yard? because people were dying to get in " @@ -160,42 +187,68 @@ def joke(): print "I sold my vacuum the other day, all it was doing was collecting dust " speak("I sold my vacuum the other day... all it was doing was collecting dust") -#user_prompt() + +user_prompt() + + # tells user 1 of three random jokes def date_time(): + """ + tells user what the date and time are + :return: None + """ localtime = time.asctime(time.localtime(time.time())) print "the current time is: ", localtime speak("the current time is" + localtime) user_prompt() - #tells user the date and time + # tells user the date and time + + def send_to_printer(): + """ + creates temporary file and prints text to the default printer + :return: None + """ print "what do you want to print" speak("what do you want to print") ans = listen() print ans - filename = tempfile.mktemp (".txt") - open (filename, "w").write (ans) - win32api.ShellExecute ( - 0, - "print", - filename, - # - # If this is None, the default printer will - # be used anyway. - # - '/d:"%s"' % win32print.GetDefaultPrinter (), - ".", - 0 + filename = tempfile.mktemp(".txt") + open(filename, "w").write(ans) + win32api.ShellExecute( + 0, + "print", + filename, + # + # If this is None, the default printer will + # be used anyway. + # + '/d:"%s"' % win32print.GetDefaultPrinter(), + ".", + 0 ) # sends something to default printer - print "sent",ans,"to printer" + print "sent", ans, "to printer" + + +def user_help(): + """ + tells user what the program can do + :return: None + """ + + print "You can send emails, print, check the time, ask for a joke, if mic cant pick up audio, try changing locations or checking internet connection" + speak("You can send emails, print, check the time, ask for a joke," + + " if mic cant pick up audio, try changing locations or checking internet connection") + def main(): user_prompt() + main() From d0d8436a06e76e7d51b471546b0ba698ea9620a2 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 16 Jun 2016 10:18:39 -0700 Subject: [PATCH 3/7] edited send email function --- speech.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/speech.py b/speech.py index 36a4ed9..0244e89 100644 --- a/speech.py +++ b/speech.py @@ -66,7 +66,6 @@ def user_prompt(): while prompt == False: - usage_list = ["EMAIL", "PRINTER", "JOKE"] print "what would you like to do? Email,? Check printer?" speak("what would you like to do?") user_res = listen().upper() @@ -92,10 +91,9 @@ def user_prompt(): user_help() prompt = True - - else: print "invalid command" + speak("invalid command") prompt = False @@ -160,9 +158,11 @@ def send_email(): print msg server.sendmail(user_dict[user], contact_dict[send_to], msg) print "email sent" + speak("email sent") else: print "that name is not in your contacts " + speak("that name is not in your contacts ") server.quit() user_prompt() @@ -250,5 +250,4 @@ def user_help(): def main(): user_prompt() - main() From a19beea32b0fa0e14156957301a2b020af14ea67 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 16 Jun 2016 11:35:51 -0700 Subject: [PATCH 4/7] added exit function --- speech.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/speech.py b/speech.py index 0244e89..10b8f19 100644 --- a/speech.py +++ b/speech.py @@ -91,6 +91,10 @@ def user_prompt(): user_help() prompt = True + elif "EXIT" in user_res: + #exit() + prompt = True + else: print "invalid command" speak("invalid command") @@ -109,7 +113,6 @@ def email_prompt(): print ans if ans == "yes": - print ans print "get ready to email:" speak("get ready to email") send_email() @@ -234,6 +237,7 @@ def send_to_printer(): # sends something to default printer print "sent", ans, "to printer" + user_prompt() def user_help(): @@ -246,6 +250,16 @@ def user_help(): speak("You can send emails, print, check the time, ask for a joke," + " if mic cant pick up audio, try changing locations or checking internet connection") + user_prompt() + +def exit(): + """ + exits program by not calling the user prompt function at the end + :return: None + """ + + print "exiting program, goodbye" + speak("exiting program, goodbye") def main(): user_prompt() From f1058b1e7b92296688bac4a0562667bca6edde43 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 17 Jun 2016 14:52:06 -0700 Subject: [PATCH 5/7] added music and program function --- speech.py | 101 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 10 deletions(-) diff --git a/speech.py b/speech.py index 10b8f19..66196fb 100644 --- a/speech.py +++ b/speech.py @@ -7,6 +7,8 @@ import tempfile import win32api import win32print +import os + speech_engine = pyttsx.init('sapi5') # see http://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init speech_engine.setProperty('rate', 150) @@ -18,6 +20,12 @@ pass_dict = {"MATTHEW": "Mh1097465", "ANDREW": "temp"} +music_dict = {"SONG ONE":"C:\Users\Matthew\Desktop\song1.mp3", "SONG TWO" : ""} + +program_dict = {"NOTES":"C:\Users\Matthew\Desktop\openme.txt", "EDITOR": "C:\Program Files\Sublime Text 3\sublime_text.exe" } + + + def speak(text): """ @@ -87,12 +95,21 @@ def user_prompt(): send_to_printer() prompt = True - elif "HELP" in user_res: - user_help() + elif "RUN" in user_res or "FILE" in user_res or "PROGRAM" in user_res: + open_program() prompt = True + elif "SONG" in user_res or "MUSIC" in user_res: + play_music() + prompt = True + + elif "HELP" in user_res: + user_help() + prompt = True + elif "EXIT" in user_res: - #exit() + print "hi" + exit_program() prompt = True else: @@ -153,7 +170,7 @@ def send_email(): speak("who do you want to send this to") send_to = listen().upper() print send_to - # you need a while loop here + if send_to in contact_dict: speak("what do you want to say to" + contact_dict[send_to]) @@ -191,10 +208,7 @@ def joke(): speak("I sold my vacuum the other day... all it was doing was collecting dust") -user_prompt() - - -# tells user 1 of three random jokes + user_prompt() def date_time(): """ @@ -218,7 +232,7 @@ def send_to_printer(): print "what do you want to print" speak("what do you want to print") ans = listen() - print ans + print ans.upper filename = tempfile.mktemp(".txt") open(filename, "w").write(ans) @@ -239,6 +253,71 @@ def send_to_printer(): print "sent", ans, "to printer" user_prompt() +def open_program(): + """ + opens a program of the users choice + :return: + """ + + print "which program or file do you want to open?" + speak("which program or file do you want to open?") + ans = listen().upper() + print ans + + if ans == "NOTEPAD": + try: + print "yes" + os.startfile("C:\Users\Matthew\Desktop\openme.txt") + + except Exception, e: + print "no" + print str(e) + + elif ans == "SUBLIME TEXT": + try: + print "yes" + os.startfile("C:\Program Files\Sublime Text 3\sublime_text.exe") + + except Exception, e: + print"no" + print str(e) + + user_prompt() + +def play_music(): + """ + prompts user for which song they want to play and opens it + :return: None + """ + + print "which song do you want to play" + speak("which song do you want to play") + ans = listen() + print ans + + if ans.upper() in music_dict: + + try: + if ans == "SONG ONE": + + print "playing", ans + speak("playing" + ans) + os.startfile("C:\Users\Matthew\Desktop\song One.mp3") # fix space problem + + elif ans == "SONG TWO": + print "playing", ans + speak("playing" + ans) + os.startfile("C\Users\Matthew\Desktop\song Two.mp3") + + except Exception, e: + print"no" + print str(e) + + else: + print "that song is not on the list" + speak("That song is not on the list ") + play_music() + def user_help(): """ @@ -252,7 +331,7 @@ def user_help(): user_prompt() -def exit(): +def exit_program(): """ exits program by not calling the user prompt function at the end :return: None @@ -261,7 +340,9 @@ def exit(): print "exiting program, goodbye" speak("exiting program, goodbye") + def main(): user_prompt() + main() From 2d2d497fbb1903ad4acc60b0af60231d402f5ce0 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sun, 19 Jun 2016 19:34:17 -0700 Subject: [PATCH 6/7] Final commit --- speech.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/speech.py b/speech.py index 66196fb..3a668da 100644 --- a/speech.py +++ b/speech.py @@ -1,6 +1,6 @@ import smtplib import speech_recognition -import pyttsx +import pyttsx #text to speech from random import randint import time # printer stuff @@ -16,13 +16,13 @@ contact_dict = {"MATTHEW": "matthew.hope16@ycdsbk12.ca", "MATT": "matt-hope@hotmail.com", "ANDREW": "andrewhope772@gmail.com"} -user_dict = {"MATTHEW": "matthew.hope16@ycdsbk12.ca", "ANDREW": "andrewhope772@gmail.com"} +user_dict = {"MATTHEW": "matthew.hope16@ycdsbk12.ca", "ANDREW": "temp"} -pass_dict = {"MATTHEW": "Mh1097465", "ANDREW": "temp"} +pass_dict = {"MATTHEW": "temp", "ANDREW": "temp"} music_dict = {"SONG ONE":"C:\Users\Matthew\Desktop\song1.mp3", "SONG TWO" : ""} -program_dict = {"NOTES":"C:\Users\Matthew\Desktop\openme.txt", "EDITOR": "C:\Program Files\Sublime Text 3\sublime_text.exe" } +program_dict = {"NOTES":"C:\Users\Matthew\Desktop\openme.txt", "SUBLIME TEXT": "C:\Program Files\Sublime Text 3\sublime_text.exe" } @@ -292,7 +292,7 @@ def play_music(): print "which song do you want to play" speak("which song do you want to play") - ans = listen() + ans = listen().upper() print ans if ans.upper() in music_dict: From 006c7c63da0a08109c3a80987edcb745b59cbba3 Mon Sep 17 00:00:00 2001 From: matthope1 Date: Mon, 25 May 2020 20:45:38 -0400 Subject: [PATCH 7/7] BRUH fixed leaked info --- speech.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/speech.py b/speech.py index 3a668da..56087b7 100644 --- a/speech.py +++ b/speech.py @@ -13,10 +13,9 @@ speech_engine = pyttsx.init('sapi5') # see http://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init speech_engine.setProperty('rate', 150) -contact_dict = {"MATTHEW": "matthew.hope16@ycdsbk12.ca", "MATT": "matt-hope@hotmail.com", - "ANDREW": "andrewhope772@gmail.com"} +contact_dict = {"MATTHEW": "matthew.template@mail.ca"} -user_dict = {"MATTHEW": "matthew.hope16@ycdsbk12.ca", "ANDREW": "temp"} +user_dict = {"MATTHEW": "matthew.template@mail.ca", "ANDREW": "temp"} pass_dict = {"MATTHEW": "temp", "ANDREW": "temp"}