Einfache Regex Check Demo
This commit is contained in:
24
main.py
24
main.py
@@ -5,6 +5,7 @@ import time
|
||||
import os
|
||||
import subprocess
|
||||
import sounddevice as sd
|
||||
import re
|
||||
|
||||
#test
|
||||
|
||||
@@ -12,7 +13,7 @@ import sounddevice as sd
|
||||
# KONFIGURATION
|
||||
# =========================
|
||||
|
||||
VOSK_MODEL_PATH = "/home/tino/Desktop/Abschlussprojekt/test assistant/cloneAssistantAllInOne/RasPi_Voice_Assistant--WIP/vosk-model-de-0.21"
|
||||
VOSK_MODEL_PATH = "/home/tino/Desktop/Abschlussprojekt/test assistant/cloneAssistantAllInOne/vosk-model-de-0.21/"
|
||||
PIPER_BIN = "piper"
|
||||
PIPER_MODEL = "de_DE-thorsten-medium.onnx"
|
||||
SAMPLE_RATE = 22050
|
||||
@@ -102,6 +103,7 @@ def timer_skill(slots):
|
||||
duration = slots["duration"]
|
||||
return f"Der Timer für {duration} Minuten wurde gestartet."
|
||||
|
||||
|
||||
SKILLS = {
|
||||
"weather": weather_skill,
|
||||
"timer": timer_skill
|
||||
@@ -135,6 +137,8 @@ def handle_text(text):
|
||||
context["intent"] = intent
|
||||
context["required_slots"] = INTENTS[intent]["required_slots"]
|
||||
|
||||
check_required(text)
|
||||
|
||||
# 3. Fehlende Slots prüfen
|
||||
for slot in context["required_slots"]:
|
||||
if slot not in context["slots"]:
|
||||
@@ -147,6 +151,24 @@ def handle_text(text):
|
||||
speak(result)
|
||||
reset_context()
|
||||
|
||||
def check_required(text):
|
||||
if context["intent"] == "weather" or context["pending_slot"] != None:
|
||||
if not re.search(r'in\b', text):
|
||||
print("LOCATION ABFRAGEN")
|
||||
|
||||
else:
|
||||
print("LOCATION ERMITTELN")
|
||||
context["pending_slot"] = None
|
||||
|
||||
elif context["intent"] == "timer":
|
||||
if not re.search(r'\b(sekunde|minute|stunde)n?\b', text):
|
||||
print("DURATION ABFRAGEN")
|
||||
else:
|
||||
print("DURATION ERMITTELN")
|
||||
context["pending_slot"] = None
|
||||
|
||||
|
||||
|
||||
|
||||
def ask_for_slot(slot):
|
||||
questions = {
|
||||
|
||||
Reference in New Issue
Block a user