feat: onnx intent classifier replacing fuzzy match
This commit is contained in:
parent
9cb55f4730
commit
6a710c55b8
3 changed files with 94 additions and 10 deletions
19
main.py
19
main.py
|
|
@ -27,6 +27,7 @@ from rich import print
|
|||
|
||||
import config
|
||||
import tts
|
||||
from intent import IntentClassifier
|
||||
|
||||
# some consts
|
||||
CDIR = os.getcwd()
|
||||
|
|
@ -60,6 +61,9 @@ VAD_FRAME_MS = 30
|
|||
VAD_FRAME_BYTES = int(samplerate * VAD_FRAME_MS / 1000) * 2
|
||||
vad = webrtcvad.Vad(config.VAD_AGGRESSIVENESS)
|
||||
|
||||
intent_classifier = IntentClassifier()
|
||||
intent_classifier.prime({c: v['phrases'] for c, v in VA_CMD_LIST.items()})
|
||||
|
||||
|
||||
def gpt_answer():
|
||||
global message_log
|
||||
|
|
@ -140,9 +144,10 @@ def va_respond(voice: str):
|
|||
|
||||
print(cmd)
|
||||
|
||||
min_percent = int(round(config.INTENT_SIMILARITY_THRESHOLD * 100))
|
||||
if len(cmd['cmd'].strip()) <= 0:
|
||||
return False
|
||||
elif cmd['percent'] < 70 or cmd['cmd'] not in VA_CMD_LIST.keys():
|
||||
elif cmd['percent'] < min_percent or cmd['cmd'] not in VA_CMD_LIST.keys():
|
||||
# play("not_found")
|
||||
# tts.va_speak("Что?")
|
||||
if fuzz.ratio(voice.join(voice.split()[:1]).strip(), "скажи") > 75:
|
||||
|
|
@ -179,15 +184,9 @@ def filter_cmd(raw_voice: str):
|
|||
|
||||
|
||||
def recognize_cmd(cmd: str):
|
||||
rc = {'cmd': '', 'percent': 0}
|
||||
for c, v in VA_CMD_LIST.items():
|
||||
for x in v['phrases']:
|
||||
vrt = fuzz.ratio(cmd, x)
|
||||
if vrt > rc['percent']:
|
||||
rc['cmd'] = c
|
||||
rc['percent'] = vrt
|
||||
|
||||
return rc
|
||||
candidates = {c: v['phrases'] for c, v in VA_CMD_LIST.items()}
|
||||
res = intent_classifier.match(cmd, candidates)
|
||||
return {'cmd': res['cmd'], 'percent': int(round(res['score'] * 100))}
|
||||
|
||||
|
||||
def _set_mute(state: int):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue