-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (56 loc) · 1.65 KB
/
Copy pathmain.py
File metadata and controls
62 lines (56 loc) · 1.65 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
import speech_recognition as sr
import webbrowser
import pyttsx3
import search
import requests
import genai
#you can also use gtts as text to speech reply
#you can also use pocketsphinx as speech recognizer
def getNews():
url = ('https://newsapi.org/v2/top-headlines?country=us&apiKey=0175f2ba50344b36b523c7b00ccf4101')
response = requests.get(url)
return response.json()
recognizer=sr.Recognizer()
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
def say():
with sr.Microphone() as source:
audio = r.listen(source, timeout=5,phrase_time_limit=1.5)
word=r.recognize_google(audio)
return word
def commandProcessed(c):
print(c)
i = c.lower()
if i in search.objects.keys():
speak(f'opening {i.split(' ')[-1]}')
webbrowser.open(search.objects[i])
elif i in search.songs.keys():
speak(f'playing {i}')
webbrowser.open(search.songs[i])
elif i=='news':
a=getNews()
for i in range(5):
speak(a['articles'][i]['title'])
else:
a= genai.res(i)
speak(a)
if __name__ == "__main__":
speak("Friday is active now...")
while True:
r = sr.Recognizer()
try:
print("Say something!")
word=say()
print(word)
if(word.lower()=='friday'):
speak('Sir, How can I help you')
print("give your command")
command=say()
commandProcessed(command)
elif(word.lower()=='please stop'):
speak('goodbye sir')
break
except Exception as e:
print(f"Error: {e}")