-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
112 lines (85 loc) · 2.75 KB
/
main.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
import speech_recognition as sr
import win32com.client
import webbrowser
from AppOpener import open
import openai
import os
import builtins
import random
def takeCommand():
r = sr.Recognizer()
# taking input from mic
with sr.Microphone() as source:
r.pause_threshold = 1
audio = r.listen(source)
try:
search = r.recognize_google(audio, language="en-in")
print(f"User Said: {search}")
return search
# Output as voice
except Exception:
e = "Some Error Occurred"
print(e)
return "clear"
def say(ans):
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak(ans)
def chat(query):
global chatStr
openai.api_key = "your open api key here"
chatStr = f"User: {query}\n Jarvis: "
response = openai.Completion.create(
model="text-davinci-003",
prompt=chatStr,
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
# todo: wrap this in a try catch
say(ans=response["choices"][0]["text"])
chatStr += f"{response['choices'][0]['text']}\n "
if not os.path.exists("Openai"):
os.mkdir("Openai")
with builtins.open(f"D:\programming\jarvis Ai\Openai\{f'data {random.randint(1, 10000000000)}'}.txt", "w") as f:
f.write(chatStr)
print(chatStr)
if __name__ == "__main__":
while True:
print("Listening...")
query = takeCommand()
if f"Open youtube".lower() in query.lower():
webbrowser.open("https://www.youtube.com")
break
elif f"Open github".lower() in query.lower():
webbrowser.open("https://www.github.com")
break
elif f"Open google".lower() in query.lower():
webbrowser.open("https://www.google.com")
break
elif f"Open wikipedia".lower() in query.lower():
webbrowser.open("https://www.wikipedia.com")
break
elif "Open edge".lower() in query.lower():
open("Microsoft edge")
say(ans="opening edge")
break
elif "Open brave".lower() in query.lower():
open("brave")
say(ans="opening brave")
break
elif "Open chrome".lower() in query.lower():
open("google chrome")
say(ans="opening google chrome")
break
elif "open spotify".lower() in query.lower():
open("spotify")
say(ans="opening spotify")
break
elif "open valorant ".lower() in query.lower():
open("valorant")
say(ans="opening valorant")
break
else:
chat(query)