-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
71 lines (58 loc) · 1.61 KB
/
project.py
File metadata and controls
71 lines (58 loc) · 1.61 KB
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
import pyttsx3 as p
import speech_recognition as sr
from News import *
import randfacts
from jokes import *
engine =p.init()
rate=engine.getProperty('rate')
engine.setProperty('rate',180)
voices= engine.getProperty('voices')
engine.setProperty('voice',voices[1].id)
# print(voices)
def speak (text):
engine.say(text)
engine.runAndWait()
r=sr.Recognizer()
speak("hello there I am your voice assisstant . How are you?")
try:
with sr.Microphone() as source:
r.energy_threshold=10000
r.adjust_for_ambient_noise(source,1.2)
print("listening..")
audio=r.listen(source)
text=r.recognize_google(audio)
print(text)
except:
print("Audio not Recognised")
if "what" and "about" and "you" in text:
speak("I am having a good day sir")
speak("What can i do for you?")
try:
with sr.Microphone() as source:
r.energy_threshold=10000
r.adjust_for_ambient_noise(source,1.2)
print("listening....")
audio=r.listen(source)
text2=r.recognize_google(audio)
print(text2)
except:
print("Audio not recognised")
if "news" in text2:
print("Sure sir, Now I will read news for you .")
speak("Sure sir, Now I will read news for you .")
arr= news()
for i in range(len(arr)):
speak(arr[i])
print(arr[i])
elif "joke" or "jokes" in text2:
speak("Sure sir, get ready for some chuckles.")
arr=joke()
print(arr[0])
speak(arr[0])
print(arr[1])
speak(arr[1])
elif "fact" or "facts" in text2:
speak("Sure sir,")
x=randfacts.getFact()
print(x)
speak("Did you know that," +x)