From 0e1c8711ade2a4f64d71d36d7900661c14d966fa Mon Sep 17 00:00:00 2001 From: AyushSatyam <42187810+AyushSatyam@users.noreply.github.com> Date: Sat, 4 Apr 2020 10:21:43 +0530 Subject: [PATCH] using microsoft speech engin and send an email,write a note,search a person on wikipedia commands are added --- .vscode/launch.json | 16 +++++++ 2020-04-03 16-40-41.703384-note.txt | 1 + 2020-04-03 17-47-42.839802-note.txt | 1 + audio.mp3 | Bin 0 -> 3072 bytes main.py | 69 ++++++++++++++++++++++++++-- 5 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 2020-04-03 16-40-41.703384-note.txt create mode 100644 2020-04-03 17-47-42.839802-note.txt create mode 100644 audio.mp3 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..092a03f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + {"name":"Python: main","type":"python","request":"launch","program":"${file}","console":"integratedTerminal"}, + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/2020-04-03 16-40-41.703384-note.txt b/2020-04-03 16-40-41.703384-note.txt new file mode 100644 index 0000000..f292b8e --- /dev/null +++ b/2020-04-03 16-40-41.703384-note.txt @@ -0,0 +1 @@ +my name is \ No newline at end of file diff --git a/2020-04-03 17-47-42.839802-note.txt b/2020-04-03 17-47-42.839802-note.txt new file mode 100644 index 0000000..39d367e --- /dev/null +++ b/2020-04-03 17-47-42.839802-note.txt @@ -0,0 +1 @@ +film \ No newline at end of file diff --git a/audio.mp3 b/audio.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..a13273785caae8847b404afe016b0cc036cdf903 GIT binary patch literal 3072 zcmeIxX;jl!769;nSY!!=Bm^2Hm=u8$1Pu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Y>0^6S>H;GNZ%J06edzZSXV}4jwAQ5O#k3FSdKOWT7$he$Eg~&gH^mtZUzAwbT#g_XOa?{25iJZkv`$Mz3%VLjNRtxcc+H=zZeef00lXL}b70(z)Lxfd{(bW00j52grJ$`Q9j#3yD~S3Nid2aX z1}2_oaKnt!rk1up)>zL<={IijIA;4!s!JlGBC#ol-Sr7S`&5 zl`TyN^#j?IriHyFF`ZE@1iuCw@n)@Zf;iiI=zL*$*;MSlsQ{{dSiSv1m%kMgFIn1I z{$e;JC6ZfIei`+|?&sHV>B*-HE1P^#{b|T2DQAIkN(LL+c3g6+;QiuyIZRRC%YYZO z=H*Zo+b^AVtAbv*PuOFbHR@<*H4$20djZ2J!CNEG@zVycXP6l!*LuU`0>27m+_Its zzDav{L^L2R-7gYBVM`@n;)w?JupvAGJ#sfbiP4*5SaLh$4gt^S@lur zZ3#%z#N4lIk5m&AG7IH@kQI&`bU3}G4X&?TTz!~`+@L8z093tOPD7!{&q2C2xB{(m zRHa`qX$i^Y5zp0#6&=p}@)n%KtgKTLm#Ar;FI(Mbvob{aiE51Wb0i3CRJZ*cYBfQ9 z_7o%gj*_9_Aw3f)4!}58n`Q^@&Z}wCnUB}7HnkG@MexD~DlkB$^7=KibdDa(kF7a+ z!n~Do#f-1y=5^mgeb2?j*$| zBK5yL`3vpOssH$m3e!gbpr=FQZ}PbSAZ`tOiU0e58iQ!Q|L)J9vj6+R-|hba_uXd> literal 0 HcmV?d00001 diff --git a/main.py b/main.py index 451fd4a..98e09df 100644 --- a/main.py +++ b/main.py @@ -15,13 +15,20 @@ """ import speech_recognition as sr import os -import pyttsx3 +#import pyttsx3 #from gtts import gTTS +import win32com.client as wincl import datetime import warnings import calendar import random import wikipedia +import subprocess +import webbrowser +import smtplib +import requests +import re +#from weather import Weather #Ignore any warnings warnings.filterwarnings('ignore') @@ -30,6 +37,8 @@ def recordAudio(): r = sr.Recognizer() with sr.Microphone() as source: print('Say something: ') + r.pause_threshold = 1 + r.adjust_for_ambient_noise(source, duration=1) audio = r.listen(source) data = "" @@ -44,9 +53,8 @@ def recordAudio(): # Function to get the virtual assistant response def assistantResponse(text): print(text) - engine = pyttsx3.init() - engine.say(text) - engine.runAndWait() + speak = wincl.Dispatch("SAPI.SpVoice") + speak.Speak(text) def wakeWord(text): WAKE_WORDS = ['hey computer','ok computer'] @@ -84,6 +92,14 @@ def getPerson(text): if i + 3 <= len(wordList) -1 and wordList[i].lower() == 'who' and wordList[i+1].lower() == 'is': return wordList[i+2] + ' '+ wordList[i+3] +def note(text): + date = datetime.datetime.now() + file_name = str(date).replace(":", "-") + "-note.txt" + with open(file_name, "w") as f: + f.write(text) + + subprocess.Popen(["notepad.exe", file_name]) + while True: # Record the audio text = recordAudio() @@ -120,7 +136,50 @@ def getPerson(text): person = getPerson(text) wiki = wikipedia.summary(person, sentences=2) response = response + ' ' + wiki - + + NOTE_STRS = ["make a note", "write this down", "remember this"] + for phrase in NOTE_STRS: + if phrase in text: + assistantResponse("What would you like me to write down?") + note_text = recordAudio() + note(note_text) + assistantResponse("I've made a note of that.") + + BREAK_WORD = ['by computer','goodbye computer','good bye'] + BREAK_RESPONCE = ['have a nice day','goodbye sir','bye','have a good day sir','goodbye and take care'] + for phrase in BREAK_WORD: + if phrase in text: + assistantResponse(random.choice(BREAK_RESPONCE)) + break + + OPEN_BROW = ['open web browser','open chrome','open google in chrome','open google search in chrome','open google chrome'] + OPEN_RESPONCE = ['done','completed','task completed','Yes, i have open it'] + for phrase in OPEN_BROW: + if phrase in text.lower(): + webbrowser.open('https://www.google.co.in/',new=2) + assistantResponse(random.choice(OPEN_RESPONCE)) + + SEND_EMAIL = ['write an email','please send an email','send an email'] + for phrase in SEND_EMAIL: + if phrase in text.lower(): + assistantResponse('write down the recipient name') + recipient = input() + server = smtplib.SMTP('64.233.184.108') + server.ehlo() + server.starttls() + server.ehlo() + #Next, log in to the server + server.login("07ayushkasera@gmail.com","satyam8546091008") + + assistantResponse('What do want to text?') + #Send the mail + msg = "\n " + recordAudio() # The /n separates the message from the headers + #fullmsg = msg.as_string() + server.sendmail("07ayushkasera@gmail.com", recipient, msg) + server.quit() + assistantResponse(random.choice(OPEN_RESPONCE)) + break + # Assistant Audio Response assistantResponse(response)