-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnity.py
More file actions
163 lines (134 loc) · 4.84 KB
/
Copy pathUnity.py
File metadata and controls
163 lines (134 loc) · 4.84 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import speech_recognition as sr
import pyttsx3
import datetime
import wikipedia
import webbrowser
import time
from python_json_config import ConfigBuilder
# create config parser
builder = ConfigBuilder()
config = builder.parse_config('config.json')
lang_file = 0
language = config.assistant.language
print(language)
if language == "de":
lang_file = builder.parse_config('lang_de.json')
elif language == "en":
lang_file = builder.parse_config('lang.json')
else:
lang_file = builder.parse_config('lang.json')
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', 'voices[0].id')
if language == "de":
engine.setProperty('voice', 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_DE-DE_ZIRA_11.0')
elif language == "en":
engine.setProperty('voice', 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0')
else:
engine.setProperty('voice', 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0')
filler_words = lang_file.filler_words
print(filler_words)
def speak(text):
engine.say(text)
engine.runAndWait()
def wishMe():
hour = datetime.datetime.now().hour
if 0 <= hour < 12:
speak(lang_file.good_morning)
elif 12 <= hour < 16:
speak(lang_file.good_noon)
else:
speak(lang_file.good_evening)
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
r_language = language
statement = r.recognize_google(audio, language=r_language + "-" + r_language)
print(f"user said:{statement}\n")
except Exception as e:
# speak("Keine Ahnung was du meinst")
return "None"
return statement
speak(lang_file.booting)
time.sleep(3)
speak(lang_file.intro)
wishMe()
print(lang_file.bye)
def comprehend():
while True:
statement = takeCommand().lower()
if statement == 0:
continue
for word in lang_file.bye:
if statement in word:
print(lang_file.bye)
speak(lang_file.shutdown)
break
exit()
for word in lang_file.wikipedia:
if word in statement:
speak(lang_file.searching_wiki)
results = ""
for word in filler_words:
if statement in word:
statement = statement.replace(word, "")
try:
wikipedia.set_lang(language)
print(statement)
results = wikipedia.summary(statement, sentences=3)
except:
print(language)
speak(lang_file.wiki_404)
print("Unity understood: " + statement)
speak(lang_file.from_wiki)
print(results)
speak(results)
for word in lang_file.google:
if statement in word:
for wrd in filler_words:
if statement in wrd:
statement = statement.replace(wrd, "")
webbrowser.open_new_tab("https://www.google.com")
speak(lang_file.google_executed)
time.sleep(5)
for word in lang_file.gmail:
if statement in word:
for wrd in filler_words:
if statement in wrd:
statement = statement.replace(wrd, "")
webbrowser.open_new_tab("gmail.com")
speak(lang_file.gmail_executed)
time.sleep(5)
for word in lang_file.stadia:
if statement in word:
for wrd in filler_words:
if statement in wrd:
statement = statement.replace(wrd, "")
webbrowser.open_new_tab("https://stadia.google.com/u/2/home")
speak(lang_file.stadia_executed)
time.sleep(5)
for word in lang_file.clock:
if statement in word:
strTime = datetime.datetime.now().strftime("%H:%M")
speak(str(lang_file.clock_msg) + strTime)
for word in lang_file.search:
if word in statement:
for wrd in filler_words:
if wrd in statement:
statement = statement.replace(wrd, "")
webbrowser.open_new_tab(statement)
time.sleep(5)
for word in lang_file.connect:
if statement in word:
from VI_AI import chat
chat()
break
for word in lang_file.shutdown_command:
if statement in word:
exit()
break
comprehend()