44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
"""Wake word detection utilities for VoIdeaAI.
|
|
|
|
Server-side wake word configuration and validation.
|
|
Actual detection is performed client-side via Web Speech API.
|
|
"""
|
|
|
|
WAKE_WORD_DEFAULTS = {
|
|
"enabled": True,
|
|
"word": "ВоИдея",
|
|
"timeout_minutes": 5,
|
|
"sensitivity": 0.7,
|
|
}
|
|
|
|
|
|
def validate_wake_word_params(params: dict | None = None) -> dict:
|
|
"""Validate and return wake word parameters with defaults."""
|
|
if not params:
|
|
return dict(WAKE_WORD_DEFAULTS)
|
|
result = dict(WAKE_WORD_DEFAULTS)
|
|
if isinstance(params.get("enabled"), bool):
|
|
result["enabled"] = params["enabled"]
|
|
if isinstance(params.get("word"), str) and params["word"].strip():
|
|
result["word"] = params["word"].strip()
|
|
if isinstance(params.get("timeout_minutes"), (int, float)):
|
|
result["timeout_minutes"] = max(1, int(params["timeout_minutes"]))
|
|
if isinstance(params.get("sensitivity"), (int, float)):
|
|
result["sensitivity"] = max(0.0, min(1.0, float(params["sensitivity"])))
|
|
return result
|
|
|
|
|
|
def strip_wake_word(text: str, wake_word: str = "ВоИдея") -> str:
|
|
"""Remove wake word prefix from text if present."""
|
|
cleaned = text.strip()
|
|
for prefix in [wake_word, wake_word.lower(), wake_word.upper()]:
|
|
if cleaned.startswith(prefix):
|
|
cleaned = cleaned[len(prefix):].strip()
|
|
break
|
|
return cleaned
|
|
|
|
|
|
def has_wake_word(text: str, wake_word: str = "ВоИдея") -> bool:
|
|
"""Check if text contains the wake word (case-insensitive)."""
|
|
return wake_word.lower() in text.lower()
|