forked from DhruvSeth18/SCM_Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v2.py
142 lines (123 loc) · 4.55 KB
/
v2.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from tkinter import *
import pyttsx3
import datetime
import speech_recognition as sr
import webbrowser
import wikipedia
import os
import openai
import pywhatkit as pwt
import datetime
root=Tk()
root.geometry("600x400+600+200")
root.configure(bg="#C9EEFF")
root.title("VOICE ASSISTANT with GPT")
f1=Frame(root,height=100,bg='yellow').pack(fill='x')
li=Label(f1,text="VOICE ASSISTANT",font =('Arial',30,'bold'),bg="yellow").place(x=75,y=25)
os.environ["OPENAI_API_KEY"] = "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"
# Retrieve the API key from the secret manager
openai.api_key = os.environ["OPENAI_API_KEY"]
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices)
engine.setProperty('voice',voices[0])
engine.setProperty('rate',185)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def greet():
time = int(datetime.datetime.now().hour)
if time<=12:
speak("Goodmorning Sir ")
elif 12<time<=18:
speak("Good Afternoon Sir")
elif 18<time<=24:
speak("Good Evening Sir")
def take():
r=sr.Recognizer()
with sr.Microphone() as source:
my_label.config(text="Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
my_label.config(text="recognising...")
query =r.recognize_google(audio,language="en-in")
except Exception as e:
print(e)
speak("can't hear")
return "None"
return query
def Listen():
global root
greet()
while 1:
query = take().lower()
print(query)
if 'rohit' in query:
query = query.replace("rohit", "")
response = openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{"role": "user", "content": query}])
text = response.choices[0].message.content
speak(text)
print(query)
elif 'Hi' in query:
speak("Hi Sir Glad to see you again")
elif 'hello' in query:
speak("Hello Sir what can i do for you ")
print(query)
elif 'what is my name' in query:
speak("Sir your name is Dhruv Seth")
print(query)
elif 'play' in query:
query=query.replace("play","")
loc=f"C:\\Users\\yootu\\Downloads\\song\\{query}.mp3"
loc=loc.replace(" ","")
os.startfile(loc)
elif 'on youtube' in query:
query=query.replace("on youtube","")
pwt.playonyt(query)
elif 'open google' in query:
webbrowser.open("google.com")
print(query)
elif 'open youtube' in query:
webbrowser.open("youtube.com")
print(query)
elif 'open instagram' in query:
webbrowser.open("instagram.com")
print(query)
elif 'great AI' in query:
speak("Thank you sir , I am always there to held you")
elif 'wikipedia' in query:
speak("Searching on wikipedia...")
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("According to wikipedia ...")
speak(results)
print(results)
elif "meaning" in query:
response = openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{"role": "user", "content": query}])
text = response.choices[0].message.content
speak(text)
print(text)
elif 'nothing' in query:
speak("ok sir if you need me just ask ")
elif 'good morning' in query:
speak("good morning sir! How may i help u.")
elif 'good afternoon' in query:
speak("good afternoon sir! How is your day going.")
elif 'good evening' in query:
speak("good evening sir! How is your day going.")
elif 'good night' in query:
speak("Good night sir! how was your day spent?")
elif "what's the time?" in query:
time2=int(datetime.datetime.now().hour)
speak("the time is"+time2)
elif ('shutdown' in query) or ('stop listen' in query) or ("don't listen" in query):
speak("Ok sir")
root.destroy()
break
#wrong change
round = PhotoImage(file="BUTTON.png")
B1=Button(root,image=round,bg="#C9EEFF",border=0,command=Listen).place(x=280,y=195)
my_label=Label(root,text="",bg="#C9EEFF")
my_label.place(x=220,y=260)
root.mainloop()