Timer übergabe mit Subaction funktioniert. Timer Funktion noch nicht implementiert
This commit is contained in:
54
main.py
54
main.py
@@ -83,12 +83,12 @@ INTENTS = {
|
||||
|
||||
"timer": {
|
||||
"keywords": ["timer"],
|
||||
"required_slots": {},
|
||||
# "required_slots": {},
|
||||
"actions":{
|
||||
"start": {
|
||||
"keywords": ["starte", "start", "beginne"],
|
||||
"keywords": ["starte", "start", "beginne", "stelle"],
|
||||
"required_slots": {
|
||||
"duration": r"(\d+)\s*(sekunden|sekunde|minuten|minute|stunden|stunde)"
|
||||
"duration": r"(\w+)\s*(sekunden|sekunde|minuten|minute|stunden|stunde)"
|
||||
}
|
||||
},
|
||||
"stop": {
|
||||
@@ -169,9 +169,32 @@ def handle_text(text):
|
||||
speak("Das habe ich nicht verstanden.")
|
||||
reset_context()
|
||||
return
|
||||
|
||||
context["intent"] = intent
|
||||
context["required_slots"] = INTENTS[intent]["required_slots"] # man könnte per liste drüber iterieren wenn man mehrere required slots hat
|
||||
|
||||
|
||||
|
||||
##NOCHMAL GENAUER ERKLÄREN LASSEN (instatt in check reqired() nach required slots check nach open nach oben verschoben damit required slots funktoinieren )
|
||||
intent_data = INTENTS[context["intent"]]
|
||||
actions = intent_data.get("actions")
|
||||
|
||||
if actions:
|
||||
for action_name, action_data in actions.items():
|
||||
if any(k in text for k in action_data.get("keywords", [])):
|
||||
context["action"] = action_name
|
||||
break
|
||||
|
||||
#Edgecase falls nutzer befehl bei dem action benötigt wird ohne action angibt
|
||||
if INTENTS[context["intent"]].get("actions") and context["action"] is None:
|
||||
speak("Ungültige Eingabe, Aktion wurde nicht genannt")
|
||||
return False
|
||||
|
||||
|
||||
if context["action"] == None:
|
||||
context["required_slots"] = INTENTS[context["intent"]]["required_slots"]
|
||||
else:
|
||||
context["required_slots"] = INTENTS[context["intent"]]["actions"][context["action"]]["required_slots"]
|
||||
|
||||
|
||||
|
||||
# 2. Fehlende Slots prüfen
|
||||
if not check_required(text):
|
||||
@@ -191,10 +214,11 @@ def handle_text(text):
|
||||
|
||||
def check_required(text):
|
||||
intent_data = INTENTS[context["intent"]]
|
||||
actions = intent_data.get("actions")
|
||||
|
||||
text = text.lower()
|
||||
|
||||
for slot, pattern in intent_data.get("required_slots", {}).items():
|
||||
#for slot, pattern in intent_data.get("required_slots", {}).items():
|
||||
for slot, pattern in context["required_slots"].items():
|
||||
if slot not in context["slots"]:
|
||||
match = re.search(pattern, text)
|
||||
if match:
|
||||
@@ -204,17 +228,12 @@ def check_required(text):
|
||||
ask_for_slot(slot)
|
||||
return False
|
||||
|
||||
##NOCHMAL GENAUER ERKLÄREN LASSEN
|
||||
if actions:
|
||||
for action_name, action_data in actions.items():
|
||||
if any(k in text for k in action_data.get("keywords", [])):
|
||||
context["action"] = action_name
|
||||
break
|
||||
|
||||
|
||||
#Edgecase falls nutzer befehl bei dem action benötigt wird ohne action angibt
|
||||
if intent_data.get("actions") and context["action"] is None:
|
||||
speak("Ungültige Eingabe, Aktion wurde nicht genannt")
|
||||
return False
|
||||
# if INTENTS[context["intent"]].get("actions") and context["action"] is None:
|
||||
# speak("Ungültige Eingabe, Aktion wurde nicht genannt")
|
||||
# return False
|
||||
|
||||
|
||||
|
||||
@@ -313,7 +332,8 @@ def real_wakeword_detector():
|
||||
time.sleep(1) #verbesserung der spracheingabe: wurde hinzugefügt weil es sonst worte halluziniert (wie "eine", "jarvis")
|
||||
state = STATE_LISTENING
|
||||
print("WAKE WORD DETECTED")
|
||||
speak("Ja, wie kann ich helfen?")
|
||||
#speak("Ja, wie kann ich helfen?")
|
||||
speak("Ja?")
|
||||
|
||||
|
||||
with sd.InputStream(
|
||||
|
||||
Reference in New Issue
Block a user