Вот мой код:
import speech_recognition as sr
import webbrowser
import os
name = open("name.txt", "w+")
with open("registr.txt", "w+") as f:
if f.read() == "1":
main()
if f.read() == "0":
comp = input("Введите имя пользователя: ")
name.write(comp)
f.write("1")
main()
# Основной цикл бота
def main():
def recognize_speech():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
audio = recognizer.listen(source)
print("Можете говорить!")
try:
text = recognizer.recognize_google(audio, language="ru-RU")
return text
except sr.UnknownValueError:
return "Извините, не могу распознать речь"
except sr.RequestError:
return "Не могу получить доступ к сервису распознавания речи"
while True:
input_text = recognize_speech()
print(input_text)
if "Найди" in input_text:
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open(f"https://yandex.ru/search/?text={input_text}&lr=63&clid=2271258&win=569")
elif "Открой ютуб" in input_text:
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open("https://youtube.com")
elif "Открой ВК" in input_text:
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open("https://vk.com")
elif "Выключи компьютер" in input_text:
os.system('shutdown /s /t 1')
elif "Скачай" in input_text:
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open(f"https://yandex.ru/search/?text={input_text}&lr=63&clid=2271258&win=569")
elif "Закрой браузер" in input_text:
os.system('taskkill chrome.exe')
else:
pass