При запуске слушания собственно написанного голосовго помощника. зависает main интерфейс и становиться недоступен
import customtkinter
import ctypes
from PIL import Image
import helper
# icon on taskbar
myappid = 'mycompany.myproduct.subproduct.version' # arbitrary string
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
#image open
focused_micro = customtkinter.CTkImage(Image.open("assets/focused_micro.png"), size=(300, 300))
enabled_micro = customtkinter.CTkImage(Image.open("assets/enabled_micro.png"), size=(300, 300))
# main script
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.unit_ui()
def unit_ui(self):
def microphone_button_callback():
if self.microphone_button.cget("text") == "on":
self.microphone_button.configure(image=enabled_micro)
self.microphone_button.configure(text="off")
helper.kaneki()
else:
self.microphone_button.configure(image=focused_micro)
self.microphone_button.configure(text="on")
# head
self.title("Голосовой помощник Осирис")
self.geometry("400x500")
self.resizable(False, False)
# main microphone button
self.microphone_button = customtkinter.CTkButton(master=self, image=focused_micro, fg_color="#242424", hover=False, text="on", text_color="#242424", command=microphone_button_callback)
self.microphone_button.place(x=50, y=60)
# author label
self.author_label_frame = customtkinter.CTkLabel(master=self, text="Made by @xxx", font=("Outfit Bold", 15), text_color="#494949")
self.author_label_frame.place(x=240, y=453)
if __name__ == "__main__":
app = App()
app.mainloop()
<- Файл с интерфейсом
Файл с кодом помощника ->
import speech_recognition
import os
import getpass
def record_and_recognize_audio(*args: tuple):
recognizer = speech_recognition.Recognizer()
microphone = speech_recognition.Microphone()
with microphone:
recognized_data = ""
recognizer.adjust_for_ambient_noise(microphone, duration=2)
try:
print("Слушаю...")
audio = recognizer.listen(microphone, 5, 5)
except speech_recognition.WaitTimeoutError:
print("Пожалуйста, посмотрите ваш микрофон включен?")
return
try:
print("Начато распознование...")
recognized_data = recognizer.recognize_google(audio, language="ru".lower())
except speech_recognition.UnknownValueError:
pass
except speech_recognition.RequestError:
print("Проверьте подключение к интернету!")
return recognized_data
def kaneki():
while True:
voice_input = record_and_recognize_audio()
if voice_input.lower() == "канеки открой проводник":
os.startfile("explorer.exe")
elif voice_input.lower() == "канеки открой калькулятор":
os.startfile("calc.exe")
elif voice_input.lower() == "канеки открой telegram":
os.startfile(f"C:/Users/{getpass.getuser()}/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Telegram Desktop/Telegram.lnk")
elif voice_input.lower() == "канеки открой chrome":
os.startfile(f"C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Google Chrome.lnk")
elif "канеки сколько будет" in voice_input.lower():
print(eval(voice_input[21:]))
elif voice_input.lower() == "канеки кто твой создатель":
print("@xxx - мой создатель :)")
elif voice_input.lower() == "канеки стоп":
break
else:
print(voice_input)