Skip to content

Commit

Permalink
using microsoft speech engin and send an email,write a note,search a …
Browse files Browse the repository at this point in the history
…person on wikipedia commands are added
  • Loading branch information
AyushSatyam committed Apr 4, 2020
1 parent 76178d0 commit 0e1c871
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
1 change: 1 addition & 0 deletions 2020-04-03 16-40-41.703384-note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my name is
1 change: 1 addition & 0 deletions 2020-04-03 17-47-42.839802-note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
film
Binary file added audio.mp3
Binary file not shown.
69 changes: 64 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 = ""
Expand All @@ -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']
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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("[email protected]","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("[email protected]", recipient, msg)
server.quit()
assistantResponse(random.choice(OPEN_RESPONCE))
break

# Assistant Audio Response
assistantResponse(response)

Expand Down

0 comments on commit 0e1c871

Please sign in to comment.