-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssistantProcessor.py
More file actions
228 lines (210 loc) · 10.9 KB
/
AssistantProcessor.py
File metadata and controls
228 lines (210 loc) · 10.9 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import vosk
import pyttsx3
import os
import webbrowser
import subprocess
import sounddevice as sd
import soundfile as sf
import random
import options as op
engine = pyttsx3.init()
def program_exit(process_name): # Выключает программы
os.system(f"taskkill /f /im {process_name}")
def open_https(https): # Открывает сайты
try:
webbrowser.open(https)
except TypeError:
print("сайт не найден")
def open_program(program, checkbox="o"): # Открывает программы
if checkbox == "o":
os.system(f"start {program}")
elif checkbox == "s":
subprocess.Popen(["explorer", program])
else:
print("CheckBoxError: You entered an incorrect checkbox value")
def open_inc_program(program, program_name): # Открывает программы по их ярлыку
try:
os.startfile(program)
except FileNotFoundError:
speak(f"Я не нашла {program_name}")
def listen(): # Слушает пользователя
print("Говорите")
audio_data2 = sd.rec(int(16000 * 8), 16000, channels=1)
sd.wait()
# Сохраните записанные аудио-данные в файл
sf.write("recorded_audio.wav", audio_data2, 16000)
# Загрузите записанные аудио-данные из файла
audio_data2, sample_rate = sf.read("recorded_audio.wav")
print(f"Вы сказали: {audio_data2}")
model = vosk.Model("vosk-model-small-ru-0.22")
recognizer = vosk.KaldiRecognizer(model, 16000)
with open("recorded_audio.wav", "rb") as audio_file:
# Чтение аудиофайла и распознавание речи
audio_data = audio_file.read()
recognizer.AcceptWaveform(audio_data)
# Получение результатов распознавания
result = recognizer.FinalResult()
print(result)
return result
def speak(text): # Создаёт голос
engine.say(text)
engine.runAndWait()
print(text)
def create_password():
list_of_symbols = ["`", "~", "1", "!", "2", "@", "3", "#", "4", "$", "5", "%", "6", "^", "7", "&", "8", "*", "9",
"(", "0", ")", "-", "_", "=", "+", "q", "Q", "w", "W", "e", "E", "r", "R", "t", "T", "y", "Y",
"u", "U", "i", "I", "o", "O", "p", "P", "[", "{", "]", "}", "a", "A", "s", "S", "d", "D", "f",
"F", "g", "G", "h", "H", "j", "J", "k", "K", "l", "L", ";", ":", "\'", "\"", "\\", "|", "z",
"Z", "x", "X", "c", "C", "v", "V", "b", "B", "n", "N", "m", "M", ",", "<", ".", ">", "/", "?"]
empty_line = ""
for i in range(8):
empty_line += list_of_symbols[random.randint(0, 94)]
print("Пароль:" + empty_line)
return empty_line
if __name__ == "__main__":
sound = True
while True:
command = listen() # Сюда попадает комманда от пользователя
if sound:
if "блокнот" in command:
os.system("notepad.exe")
speak("Открываю блокнот.")
elif "вайбер" in command:
if "открой" in command:
speak("Открываю Viber")
open_inc_program("C:/Users/Валюша/Desktop/Viber", "вайбер")
elif "закрой" in command:
speak("Закрываю Viber")
program_exit("Viber.exe")
elif "включи" in command:
if "беззвучный" in command:
speak("Включаю беззвучный режим!")
sound = False
elif "выход" in command:
speak("До свидания!")
exit()
elif "гугл" in command:
if "ютуб" in command:
if "открой" in command:
speak("Открываю Google YouTube")
open_inc_program("C:/Users/Валюша/Desktop/Google YouTube", "ютуб")
elif "хром" in command:
if "открой" in command:
speak("Открываю Google Chrome")
open_inc_program("C:/Users/Валюша/Desktop/Google Chrome", "гул хром")
elif "закрой" in command:
speak("Закрываю Google Chrome")
program_exit("chrome.exe")
elif "зум" in command:
if "открой" in command:
speak("Открываю Zoom")
open_program(r'C:\Users\Валюша\AppData\Roaming\Zoom\bin\Zoom.exe', "зум")
elif "закрой" in command:
speak("Закрываю Zoom")
program_exit("Zoom.exe")
elif "игрушку" in command:
if "открой" in command:
speak("Открываю powder toy")
open_inc_program("C:/Users/Валюша/Desktop/The powder toy", "порошковая игрушка")
elif "закрой" in command:
speak("Закрываю powder toy")
program_exit("Powder.exe")
elif "наклейки" in command:
if "открой" in command:
speak("Открываю Погоду")
open_inc_program("C:/Users/Валюша/AppData/Roaming/Microsoft/Internet Explorer/Quick Launch/"
"Наліпки", "наклейки")
elif "открой" in command:
open_https(op.open_command(command))
elif "параметры" in command:
op.start()
elif "погоду" in command:
if "открой" in command:
speak("Открываю Погоду")
open_inc_program("C:/Users/Валюша/AppData/Roaming/Microsoft/Internet Explorer/Quick Launch/"
"Погода", "погода")
elif "придумай" in command:
if "пароль" in command:
speak("Пароль:" + create_password())
elif "холст" in command:
if "открой" in command:
speak("Открываю Canva")
open_inc_program("C:/Users/Валюша/Desktop/Canva", "канва")
elif "закрой" in command:
speak("Закрываю Canva")
program_exit("Canva.exe")
else:
speak("Я Вас не поняла!")
else:
if "блокнот" in command:
print(os.system("notepad.exe"))
os.system("notepad.exe")
print("Открываю блокнот.")
elif "вайбер" in command:
if "открой" in command:
print("Открываю Viber")
open_inc_program("C:/Users/Валюша/Desktop/Viber", "вайбер")
elif "закрой" in command:
print("Закрываю Viber")
program_exit("Viber.exe")
elif "выключи" in command:
if "беззвучный" in command:
print("Выключаю беззвучный режим!")
sound = True
elif "выход" in command:
print("До свидания!")
exit()
elif "гугл" in command:
if "ютуб" in command:
if "открой" in command:
print("Открываю Google YouTube")
open_inc_program("C:/Users/Валюша/Desktop/Google YouTube", "ютуб")
elif "хром" in command:
if "открой" in command:
print("Открываю Google Chrome")
open_inc_program("C:/Users/Валюша/Desktop/Google Chrome", "гул хром")
elif "закрой" in command:
print("Закрываю Google Chrome")
program_exit("chrome.exe")
elif "зум" in command:
if "открой" in command:
print("Открываю Zoom")
open_program(r'C:\Users\Валюша\AppData\Roaming\Zoom\bin\Zoom.exe', "зум")
elif "закрой" in command:
print("Закрываю Zoom")
program_exit("Zoom.exe")
elif "игрушку" in command:
if "открой" in command:
print("Открываю powder toy")
open_inc_program("C:/Users/Валюша/Desktop/The powder toy", "порошковая игрушка")
elif "закрой" in command:
print("Закрываю powder toy")
program_exit("Powder.exe")
elif "наклейки" in command:
if "открой" in command:
print("Открываю Погоду")
open_inc_program("C:/Users/Валюша/AppData/Roaming/Microsoft/Internet Explorer/Quick Launch/"
"Наліпки", "наклейки")
elif "открой" in command:
print("Открываю")
open_https(op.open_command(command))
elif "параметры" in command:
print("Открываю параметры")
op.start()
elif "погоду" in command:
if "открой" in command:
print("Открываю Погоду")
open_inc_program("C:/Users/Валюша/AppData/Roaming/Microsoft/Internet Explorer/Quick Launch/"
"Погода", "погода")
elif "придумай" in command:
if "пароль" in command:
print("Пароль:" + create_password())
elif "холст" in command:
if "открой" in command:
print("Открываю Canva")
open_inc_program("C:/Users/Валюша/Desktop/Canva", "канва")
elif "закрой" in command:
print("Закрываю Canva")
program_exit("Canva.exe")
else:
print("Я Вас не поняла!")