-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
66 lines (49 loc) · 1.36 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import requests
import json
import re
import pyttsx3
import os
from extensions.log import generate_uuid, log_msg, setup_logfile
from extensions.speech import recg_speech
from dotenv import load_dotenv
from typing import Dict
load_dotenv("./secret.env")
def get_resp(msg: str) -> Dict | None:
uuid = generate_uuid()
raw = requests.get(
"http://api.brainshop.ai/get/",
{
"bid": os.getenv("BS_ID"),
"key": os.getenv("BS_KEY"),
"uid": uuid,
"msg": msg,
},
)
_resp = json.loads(raw.content)["cnt"]
log_msg(uuid, msg, _resp)
return _resp
def _run():
# * Init TTS
engine = pyttsx3.init()
engine.setProperty("rate", 150)
engine.setProperty("voice", engine.getProperty("voices")[0])
while True:
# // TODO: Speech recognition
try:
_msg = recg_speech()
print(f"💬 > {_msg}")
resp = re.sub(
r"<([a-z]+)(?![^>]*\/>)[^>]*> *[a-zA-Z0-9]+ *<(\/[a-z]+)>",
"",
get_resp(_msg),
)
print(f"🤖 > {resp}")
# * TTS
engine.say(resp)
engine.runAndWait()
except KeyboardInterrupt:
quit(0)
if __name__ == "__main__":
os.system('cls' if os.name == 'nt' else 'clear')
setup_logfile()
_run()