forked from shankarkharel/assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assist.py
85 lines (69 loc) · 1.91 KB
/
assist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import os
import smtplib
import pythoncom
import requests
res = requests.get('https://ipinfo.io/')
data = res.json()
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[1].id)
#print(voices[1].id)
#print(voices)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():
hrs = int(datetime.datetime.now().hour)
if hrs>=12 and hrs<0:
speak("good morning!")
elif hrs>=0 and hrs<5:
speak("good afternoon!")
elif hrs>5 and time<8:
speak('good evening!')
else:
speak("hello there!")
def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("listening....")
r.pause_threashold = 3
audio = r.listen(source)
query = None
try:
print("recogniting...")
query = r.recognize_google(audio,language='en-uk')
print(f"user said : {query}\n")
except Exception as e:
speak("please say that again..")
query = None
return query
#program starts.
speak("i am assistant to this device.")
speak('how can i help you?')
wishme()
query=takecommand()
#logic for executing task.
if 'exit'in query.lower():
say('thank you!')
elif 'Wikipedia' in query:
speak("searching wikipedia....")
query = query.replace("wikipedia","")
results = wikipedia.summary(query,sentences=3)
speak(results)
elif 'open youtube' in query.lower():
speak('opening youtube')
webbrowser.open("youtube.com")
elif 'open facebook' in query.lower():
speak('facebook is opening')
webbrowser.open("https://www.facebook.com/")
elif 'Google' in query:
speak('browsing to google.com')
webbrowser.open("google.com")
elif 'location' in query.lower():
speak('opening google maps')
webbrowser.open('www.google.com/maps')