commit 4f26c7562cadd55125a5a04852036162ebd7e27a Author: stud179127 Date: Sat May 17 06:13:50 2025 +0300 Выгрузка проекта diff --git a/voice-assistant-main/.gitignore b/voice-assistant-main/.gitignore new file mode 100644 index 0000000..b6e4761 --- /dev/null +++ b/voice-assistant-main/.gitignore @@ -0,0 +1,129 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/voice-assistant-main/AV.py b/voice-assistant-main/AV.py new file mode 100644 index 0000000..393071c --- /dev/null +++ b/voice-assistant-main/AV.py @@ -0,0 +1,110 @@ +# Голосовой ассистент1.0 BETA +import time +import speech_recognition as sr +from fuzzywuzzy import fuzz +import pyttsx3 +import datetime + + + +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} + +# настройки +opts = { + "alias": ('ва','голосовой помощник','голосовой ассистент','ассистент','voice assistant','помощник'), + "tbr": ('скажи', 'расскажи', 'покажи', 'сколько', 'произнеси'), + "cmds": { + "ctime": ('текущее время', 'сейчас времени', 'который час'), + "radio": ('включи музыку', 'воспроизведи радио', 'включи радио'), + "stupid1": ('расскажи анекдот', 'рассмеши меня', 'ты знаешь анекдоты','щутку'), + "weather":('погода','скажи погоду','какая сейчас погода'), + "search":('найди','найди в интернете','поищи в интернете','запрос') + } +} + + +# функции +def speak(what): + print(what) + speak_engine.say(what) + speak_engine.runAndWait() + speak_engine.stop() + + +def callback(recognizer, audio): + try: + voice = recognizer.recognize_google(audio, language="ru-RU").lower() + print("[log] Распознано: " + voice) + + if voice.startswith(opts["alias"]): + # обращение + cmd = voice + + for x in opts['alias']: + cmd = cmd.replace(x, "").strip() + + for x in opts['tbr']: + cmd = cmd.replace(x, "").strip() + + # распознаем и выполняем команду + cmd = recognize_cmd(cmd) + execute_cmd(cmd['cmd']) + + except sr.UnknownValueError: + print("[log] Голос не распознан!") + except sr.RequestError as e: + print("[log] Неизвестная ошибка, проверьте интернет!") + + +def recognize_cmd(cmd): + RC = {'cmd': '', 'percent': 0} + for c, v in opts['cmds'].items(): + + for x in v: + vrt = fuzz.ratio(cmd, x) + if vrt > RC['percent']: + RC['cmd'] = c + RC['percent'] = vrt + + return RC + + +def execute_cmd(cmd): + if cmd == 'ctime': + # сказать текущее время + now = datetime.datetime.now() + speak("Сейчас " + str(now.hour) + ":" + str(now.minute)) + + elif cmd == 'stupid1': + # рассказать анекдот + speak("1234567890") + + elif cmd == 'weather': + print('Какой ваш город ?') + import Weather + + elif cmd == 'search': + print('Какой ваш запрос ?') + import web + + else: + print('Команда не распознана, повторите!') + + + +# запуск +r = sr.Recognizer() +m = sr.Microphone(device_index=1) + +with m as source: + r.adjust_for_ambient_noise(source) + +speak_engine = pyttsx3.init() + + +speak("Добрый день, Голосовой помощник на связи") +speak("Слушаю команду") + +stop_listening = r.listen_in_background(m, callback) +while True: time.sleep(0.1) # infinity loop diff --git a/voice-assistant-main/README.md b/voice-assistant-main/README.md new file mode 100644 index 0000000..d5c2950 --- /dev/null +++ b/voice-assistant-main/README.md @@ -0,0 +1,6 @@ +Приложение работает только с поключенным интернетом, так как использует Google api +Для запуска программ требуются следующие библиотеки: +1) Pyttsx3 - эта библиотека отвечает за синтезатор речи из текста (перед ее установкой нужно установить патчи - 1 pywin32 , 2 pypiwin32) +2) SpeechRecognition - эта библиотека отвечает за распознавание речи +3) PyAudio - библиотека для ввода текста голосом (на windows при установки зачастую бывает выдает ошибки, поэтому тут уже есть готовый сборник версий этой библиотеки - https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio . Чтобы установить whl файл, просто скопируйте его название вместе с расширение, а после в консоли пропишите pip install и название скопированного файла) +4) Fuzzywuzzy - библиотека для сравнения ключевых слов, посредством которых происходят функции diff --git a/voice-assistant-main/VA.zip b/voice-assistant-main/VA.zip new file mode 100644 index 0000000..b75c6a7 Binary files /dev/null and b/voice-assistant-main/VA.zip differ diff --git a/voice-assistant-main/Weather 2.py b/voice-assistant-main/Weather 2.py new file mode 100644 index 0000000..5134459 --- /dev/null +++ b/voice-assistant-main/Weather 2.py @@ -0,0 +1,26 @@ +from bs4 import BeautifulSoup +import requests +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} + + +def weather(city): + city = city.replace(" ", "+") + res = requests.get( + f'https://www.google.com/search?q={city}&oq={city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8', headers=headers) + print("Searching...\n") + soup = BeautifulSoup(res.text, 'html.parser') + location = soup.select('#wob_loc')[0].getText().strip() + time = soup.select('#wob_dts')[0].getText().strip() + info = soup.select('#wob_dc')[0].getText().strip() + weather = soup.select('#wob_tm')[0].getText().strip() + print(location) + print(time) + print(info) + print(weather+"°C") + + +city = input("Enter the Name of City -> ") +city = city+" weather" +weather(city) +print("Have a Nice Day:)") diff --git a/voice-assistant-main/Weather.py b/voice-assistant-main/Weather.py new file mode 100644 index 0000000..ae0e43a --- /dev/null +++ b/voice-assistant-main/Weather.py @@ -0,0 +1,40 @@ +import speech_recognition as sr +import pyttsx3 +from bs4 import BeautifulSoup +import requests + +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} + +# функции +def speak(what): + print(what) + speak_engine.say(what) + speak_engine.runAndWait() + speak_engine.stop() + +# запуск +r = sr.Recognizer() +m = sr.Microphone(device_index=1) + +with m as source: + r.adjust_for_ambient_noise(source) + +speak_engine = pyttsx3.init() + +def weather(city): + city = city.replace(" ", "+") + res = requests.get( + f'https://www.google.com/search?q={city}&oq={city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8', + headers=headers) + soup = BeautifulSoup(res.text, 'html.parser') + location = soup.select('#wob_loc')[0].getText().strip() + info = soup.select('#wob_dc')[0].getText().strip() + weather = soup.select('#wob_tm')[0].getText().strip() + speak(location + " " + info + " " + weather + " Градуса по цельсию") + +with m as source: + audio = r.listen(source) +city = r.recognize_google(audio, language = 'ru-RU') +city = city+" weather" +weather(city) diff --git a/voice-assistant-main/web.py b/voice-assistant-main/web.py new file mode 100644 index 0000000..d3d9fed --- /dev/null +++ b/voice-assistant-main/web.py @@ -0,0 +1,27 @@ +import webbrowser as wb +import speech_recognition as sr +import pyttsx3 + + +r = sr.Recognizer() +m = sr.Microphone(device_index=1) +speak_engine = pyttsx3.init() + +def speak(what): + print(what) + speak_engine.say(what) + speak_engine.runAndWait() + speak_engine.stop() + +def search(srch): + wb.open(f'https://www.google.ru/search?q={srch}') + +# +with m as source: + audio = r.listen(source) +srch = r.recognize_google(audio, language = 'ru-RU') +search(srch) + + + +