Приветствую! Думаю многие видели в TikTok голосовых помощников для ПК, которые чего только не могут: открывают сайты, меняют яркость, и так далее. Так вот, сейчас мы напишем такого, на самом деле это делается очень легко и быстро. Не буду тянуть и лить воду, начинаем. Библиотеки speech_recognition — для распознавания речи. pyttsx3 — для синтеза речи. webbrowser — для открытия веб-сайтов. subprocess — для выполнения команд Windows. pyautogui — для комбинаций клавиш (смена языка, сворачивание окон) Для установки библиотек - введите команду в cmd: pip install SpeechRecognition pyttsx3 pyautogui subprocess webbrowser Код pip install SpeechRecognition pyttsx3 pyautogui subprocess webbrowser Пишем код Импортируем библиотеки: import speech_recognition as sr import subprocess import pyttsx3 import webbrowser import pyautogui Python import speech_recognition as sr import subprocess import pyttsx3 import webbrowser import pyautogui Настраиваем синтез речи: engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') engine.setProperty('voice', voices[0].id) # Выбор голоса Python engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') engine.setProperty('voice', voices[0].id) # Выбор голоса Создаем функцию озвучки текста: def speak(text): engine.say(text) engine.runAndWait() Python def speak(text): engine.say(text) engine.runAndWait() Создаем функцию распознавания речи: def recognize_speech(): recognizer = sr.Recognizer() with sr.Microphone() as source: speak("Жду ваших указаний") audio = recognizer.listen(source) try: command = recognizer.recognize_google(audio, language="ru-RU") return command except sr.UnknownValueError: return "" except sr.RequestError: return "" Python def recognize_speech(): recognizer = sr.Recognizer() with sr.Microphone() as source: speak("Жду ваших указаний") audio = recognizer.listen(source) try: command = recognizer.recognize_google(audio, language="ru-RU") return command except sr.UnknownValueError: return "" except sr.RequestError: return "" Тут мы отправляем аудио-файл на сервера гугла и получаем текст. Создаем функцию обработки команд и их выполнения: def execute_command(command): # Команды связанные с браузером if "ВК" in command.upper(): speak("Открываю ВКонтакте") webbrowser.open("https://vk.com") elif "github" in command.lower(): speak("Открываю гитхаб") webbrowser.open("https://github.com") elif "форум" in command.lower(): speak("Открываю лолз") webbrowser.open("http://lolz.live") elif "найди в гугле" in command.lower(): query = command.lower().replace("найди в гугле", "").strip() speak("Ищу в Google " + query) webbrowser.open(f"https://www.google.com/search?q={query}") # Настройки elif "яркость" in command.lower(): brightness = extract_brightness(command) if brightness is not None: set_brightness(brightness) elif "экрана" in command.lower(): speak("Открываю настройки дисплея") subprocess.Popen("control.exe desk.cpl") elif "язык" in command.lower() or "раскладка" in command.lower() or "раскладку" in command.lower(): speak("Меняю раскладку клавиатуры") pyautogui.hotkey('alt', 'shift') speak("Готово") elif "окно" in command.lower(): speak("Сворачиваю окно, сэр") pyautogui.hotkey('win', 'd') # Программы elif "калькулятор" in command.lower(): speak("Открываю калькулятор") subprocess.Popen("calc.exe") elif "блокнот" in command.lower(): speak("Открываю блокнот, сэр") subprocess.Popen("notepad.exe") else: speak('Пока что я это не умею') Python def execute_command(command): # Команды связанные с браузером if "ВК" in command.upper(): speak("Открываю ВКонтакте") webbrowser.open("https://vk.com") elif "github" in command.lower(): speak("Открываю гитхаб") webbrowser.open("https://github.com") elif "форум" in command.lower(): speak("Открываю лолз") webbrowser.open("http://lolz.live") elif "найди в гугле" in command.lower(): query = command.lower().replace("найди в гугле", "").strip() speak("Ищу в Google " + query) webbrowser.open(f"https://www.google.com/search?q={query}") # Настройки elif "яркость" in command.lower(): brightness = extract_brightness(command) if brightness is not None: set_brightness(brightness) elif "экрана" in command.lower(): speak("Открываю настройки дисплея") subprocess.Popen("control.exe desk.cpl") elif "язык" in command.lower() or "раскладка" in command.lower() or "раскладку" in command.lower(): speak("Меняю раскладку клавиатуры") pyautogui.hotkey('alt', 'shift') speak("Готово") elif "окно" in command.lower(): speak("Сворачиваю окно, сэр") pyautogui.hotkey('win', 'd') # Программы elif "калькулятор" in command.lower(): speak("Открываю калькулятор") subprocess.Popen("calc.exe") elif "блокнот" in command.lower(): speak("Открываю блокнот, сэр") subprocess.Popen("notepad.exe") else: speak('Пока что я это не умею') Создаем главный блок кода, который запускает цикл распознавания и обработки команд: if __name__ == "__main__": while True: voice_command = recognize_speech() if voice_command: execute_command(voice_command) Python if __name__ == "__main__": while True: voice_command = recognize_speech() if voice_command: execute_command(voice_command) Полный код для ленивых # Библиотеки import speech_recognition as sr import subprocess import pyttsx3 import webbrowser import wmi import os import pyautogui # Настройки озвучки engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') engine.setProperty('voice', voices[0].id) # Функция озвучки def speak(text): engine.say(text) engine.runAndWait() # Распознование голоса def recognize_speech(): recognizer = sr.Recognizer() with sr.Microphone() as source: print("Скажите что-нибудь...") speak("Жду ваших указаний") audio = recognizer.listen(source) try: print("Распознаю...") command = recognizer.recognize_google(audio, language="ru-RU") print("Вы сказали: " + command) return command except sr.UnknownValueError: print("Команда не распознана") return "" except sr.RequestError: print("Не удается подключиться к службе распознавания речи") return "" # Команды def execute_command(command): # browser, sites if "ВК" in command.upper(): speak("Открываю ВКонтакте") webbrowser.open("https://vk.com") elif "github" in command.lower(): speak("Открываю гитхаб") webbrowser.open("https://github.com") elif "форум" in command.lower(): speak("Открываю лолз=") webbrowser.open("http://lolz.live") elif "найди в гугле" in command.lower(): query = command.lower().replace("найди в гугле", "").strip() speak("Ищу в Google " + query) webbrowser.open(f"https://www.google.com/search?q={query}") # settings elif "яркость" in command.lower(): brightness = extract_brightness(command) if brightness is not None: set_brightness(brightness) elif "экрана" in command.lower(): speak("Открываю настройки дисплея, сэр") subprocess.Popen("control.exe desk.cpl") elif "язык" in command.lower() or "раскладка" in command.lower() or "раскладку" in command.lower(): speak("Меняю раскладку клавиатуры, сэр") pyautogui.hotkey('alt', 'shift') speak("Готово") elif "сделай звук" in command.lower(): volume = extract_volume(command) if volume is not None: set_volume(volume) elif "окно" in command.lower(): speak("Сворачиваю окно, сэр") pyautogui.hotkey('win', 'd') # softs elif "калькулятор" in command.lower(): speak("Открываю калькулятор") subprocess.Popen("calc.exe") elif "блокнот" in command.lower(): speak("Открываю блокнот, сэр") subprocess.Popen("notepad.exe") else: speak('Пока что я это не умею') if __name__ == "__main__": while True: voice_command = recognize_speech() if voice_command: execute_command(voice_command) Python # Библиотеки import speech_recognition as sr import subprocess import pyttsx3 import webbrowser import wmi import os import pyautogui # Настройки озвучки engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') engine.setProperty('voice', voices[0].id) # Функция озвучки def speak(text): engine.say(text) engine.runAndWait() # Распознование голоса def recognize_speech(): recognizer = sr.Recognizer() with sr.Microphone() as source: print("Скажите что-нибудь...") speak("Жду ваших указаний") audio = recognizer.listen(source) try: print("Распознаю...") command = recognizer.recognize_google(audio, language="ru-RU") print("Вы сказали: " + command) return command except sr.UnknownValueError: print("Команда не распознана") return "" except sr.RequestError: print("Не удается подключиться к службе распознавания речи") return "" # Команды def execute_command(command): # browser, sites if "ВК" in command.upper(): speak("Открываю ВКонтакте") webbrowser.open("https://vk.com") elif "github" in command.lower(): speak("Открываю гитхаб") webbrowser.open("https://github.com") elif "форум" in command.lower(): speak("Открываю лолз=") webbrowser.open("http://lolz.live") elif "найди в гугле" in command.lower(): query = command.lower().replace("найди в гугле", "").strip() speak("Ищу в Google " + query) webbrowser.open(f"https://www.google.com/search?q={query}") # settings elif "яркость" in command.lower(): brightness = extract_brightness(command) if brightness is not None: set_brightness(brightness) elif "экрана" in command.lower(): speak("Открываю настройки дисплея, сэр") subprocess.Popen("control.exe desk.cpl") elif "язык" in command.lower() or "раскладка" in command.lower() or "раскладку" in command.lower(): speak("Меняю раскладку клавиатуры, сэр") pyautogui.hotkey('alt', 'shift') speak("Готово") elif "сделай звук" in command.lower(): volume = extract_volume(command) if volume is not None: set_volume(volume) elif "окно" in command.lower(): speak("Сворачиваю окно, сэр") pyautogui.hotkey('win', 'd') # softs elif "калькулятор" in command.lower(): speak("Открываю калькулятор") subprocess.Popen("calc.exe") elif "блокнот" in command.lower(): speak("Открываю блокнот, сэр") subprocess.Popen("notepad.exe") else: speak('Пока что я это не умею') if __name__ == "__main__": while True: voice_command = recognize_speech() if voice_command: execute_command(voice_command) Озвучка режет уши, но к сожалению я не нашёл библиотеку с нормальным голосом. Также вы можете легко доработать этот скрипт под ваши нужды используя ChatGPT, его никто не отменял
ЧернильныйБро, я пытался, но: долгие ответы неправильные действия и тд крч чатгпт ещё не готов к такому
и че мне с ним делать? с одной части дома кричать "запусти помойку" запускает гта 5 рп пока я кушать грею?