Files
jarvis/main_old.py
2023-04-13 23:12:02 +05:00

81 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# КЕША 2.0
import config
import stt
import tts
from fuzzywuzzy import fuzz
import datetime
from num2t4ru import num2text
import webbrowser
import random
print(f"{config.VA_NAME} (v{config.VA_VER}) начал свою работу ...")
def va_respond(voice: str):
print(voice)
if voice.startswith(config.VA_ALIAS):
# обращаются к ассистенту
cmd = recognize_cmd(filter_cmd(voice))
if cmd['cmd'] not in config.VA_CMD_LIST.keys():
tts.va_speak("Что?")
else:
execute_cmd(cmd['cmd'])
def filter_cmd(raw_voice: str):
cmd = raw_voice
for x in config.VA_ALIAS:
cmd = cmd.replace(x, "").strip()
for x in config.VA_TBR:
cmd = cmd.replace(x, "").strip()
return cmd
def recognize_cmd(cmd: str):
rc = {'cmd': '', 'percent': 0}
for c, v in config.VA_CMD_LIST.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: str):
if cmd == 'help':
# help
text = "Я умею: ..."
text += "произносить время ..."
text += "рассказывать анекдоты ..."
text += "и открывать браузер"
tts.va_speak(text)
pass
elif cmd == 'ctime':
# current time
now = datetime.datetime.now()
text = "Сейч+ас " + num2text(now.hour) + " " + num2text(now.minute)
tts.va_speak(text)
elif cmd == 'joke':
jokes = ['Как смеются программисты? ... ехе ехе ехе',
'ЭсКьюЭль запрос заходит в бар, подходит к двум столам и спрашивает .. «м+ожно присоединиться?»',
'Программист это машина для преобразования кофе в код']
tts.va_speak(random.choice(jokes))
elif cmd == 'open_browser':
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
webbrowser.get(chrome_path).open("http://python.org")
# начать прослушивание команд
stt.va_listen(va_respond)