Einfache Regex Check Demo
This commit is contained in:
24
main.py
24
main.py
@@ -5,6 +5,7 @@ import time
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
|
import re
|
||||||
|
|
||||||
#test
|
#test
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ import sounddevice as sd
|
|||||||
# KONFIGURATION
|
# 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_BIN = "piper"
|
||||||
PIPER_MODEL = "de_DE-thorsten-medium.onnx"
|
PIPER_MODEL = "de_DE-thorsten-medium.onnx"
|
||||||
SAMPLE_RATE = 22050
|
SAMPLE_RATE = 22050
|
||||||
@@ -102,6 +103,7 @@ def timer_skill(slots):
|
|||||||
duration = slots["duration"]
|
duration = slots["duration"]
|
||||||
return f"Der Timer für {duration} Minuten wurde gestartet."
|
return f"Der Timer für {duration} Minuten wurde gestartet."
|
||||||
|
|
||||||
|
|
||||||
SKILLS = {
|
SKILLS = {
|
||||||
"weather": weather_skill,
|
"weather": weather_skill,
|
||||||
"timer": timer_skill
|
"timer": timer_skill
|
||||||
@@ -135,6 +137,8 @@ def handle_text(text):
|
|||||||
context["intent"] = intent
|
context["intent"] = intent
|
||||||
context["required_slots"] = INTENTS[intent]["required_slots"]
|
context["required_slots"] = INTENTS[intent]["required_slots"]
|
||||||
|
|
||||||
|
check_required(text)
|
||||||
|
|
||||||
# 3. Fehlende Slots prüfen
|
# 3. Fehlende Slots prüfen
|
||||||
for slot in context["required_slots"]:
|
for slot in context["required_slots"]:
|
||||||
if slot not in context["slots"]:
|
if slot not in context["slots"]:
|
||||||
@@ -147,6 +151,24 @@ def handle_text(text):
|
|||||||
speak(result)
|
speak(result)
|
||||||
reset_context()
|
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):
|
def ask_for_slot(slot):
|
||||||
questions = {
|
questions = {
|
||||||
|
|||||||
Reference in New Issue
Block a user