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": {
|
"timer": {
|
||||||
"keywords": ["timer"],
|
"keywords": ["timer"],
|
||||||
"required_slots": {},
|
# "required_slots": {},
|
||||||
"actions":{
|
"actions":{
|
||||||
"start": {
|
"start": {
|
||||||
"keywords": ["starte", "start", "beginne"],
|
"keywords": ["starte", "start", "beginne", "stelle"],
|
||||||
"required_slots": {
|
"required_slots": {
|
||||||
"duration": r"(\d+)\s*(sekunden|sekunde|minuten|minute|stunden|stunde)"
|
"duration": r"(\w+)\s*(sekunden|sekunde|minuten|minute|stunden|stunde)"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"stop": {
|
"stop": {
|
||||||
@@ -169,9 +169,32 @@ def handle_text(text):
|
|||||||
speak("Das habe ich nicht verstanden.")
|
speak("Das habe ich nicht verstanden.")
|
||||||
reset_context()
|
reset_context()
|
||||||
return
|
return
|
||||||
|
|
||||||
context["intent"] = intent
|
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
|
# 2. Fehlende Slots prüfen
|
||||||
if not check_required(text):
|
if not check_required(text):
|
||||||
@@ -191,10 +214,11 @@ def handle_text(text):
|
|||||||
|
|
||||||
def check_required(text):
|
def check_required(text):
|
||||||
intent_data = INTENTS[context["intent"]]
|
intent_data = INTENTS[context["intent"]]
|
||||||
actions = intent_data.get("actions")
|
|
||||||
text = text.lower()
|
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"]:
|
if slot not in context["slots"]:
|
||||||
match = re.search(pattern, text)
|
match = re.search(pattern, text)
|
||||||
if match:
|
if match:
|
||||||
@@ -204,17 +228,12 @@ def check_required(text):
|
|||||||
ask_for_slot(slot)
|
ask_for_slot(slot)
|
||||||
return False
|
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
|
#Edgecase falls nutzer befehl bei dem action benötigt wird ohne action angibt
|
||||||
if intent_data.get("actions") and context["action"] is None:
|
# if INTENTS[context["intent"]].get("actions") and context["action"] is None:
|
||||||
speak("Ungültige Eingabe, Aktion wurde nicht genannt")
|
# speak("Ungültige Eingabe, Aktion wurde nicht genannt")
|
||||||
return False
|
# 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")
|
time.sleep(1) #verbesserung der spracheingabe: wurde hinzugefügt weil es sonst worte halluziniert (wie "eine", "jarvis")
|
||||||
state = STATE_LISTENING
|
state = STATE_LISTENING
|
||||||
print("WAKE WORD DETECTED")
|
print("WAKE WORD DETECTED")
|
||||||
speak("Ja, wie kann ich helfen?")
|
#speak("Ja, wie kann ich helfen?")
|
||||||
|
speak("Ja?")
|
||||||
|
|
||||||
|
|
||||||
with sd.InputStream(
|
with sd.InputStream(
|
||||||
|
|||||||
Reference in New Issue
Block a user