02-ago: [proyecto] vigilancia - apagado de la tele via Alexa (VoiceMonkey monkey) tras el anuncio + audio local confirmado funcionando
This commit is contained in:
@@ -54,3 +54,6 @@ VOZ_RATE=-10%
|
||||
GOOGLE_TV_PUERTO=8500
|
||||
VOZ_MENSAJE_ALERTA=Por favor, os avisamos de que no podéis cruzar este límite. Tenéis que ir a vuestro cuarto.
|
||||
VOZ_MENSAJE_CONOCIDO={nombres}, ¿qué estás haciendo? No entres ahí.
|
||||
|
||||
# Monkey de VoiceMonkey que apaga la tele tras el anuncio (p.ej. apagar_tele)
|
||||
ALEXA_APAGAR_TV_MONKEY=
|
||||
|
||||
@@ -61,3 +61,4 @@ VOZ_MENSAJE_CONOCIDO = os.getenv(
|
||||
"VOZ_MENSAJE_CONOCIDO",
|
||||
"{nombres}, ¿qué estás haciendo? No entres ahí.",
|
||||
)
|
||||
ALEXA_APAGAR_TV_MONKEY = os.getenv("ALEXA_APAGAR_TV_MONKEY", "").strip()
|
||||
|
||||
@@ -46,6 +46,27 @@ def enviar_texto_telegram(texto: str, chat_id=None):
|
||||
print(f"[Telegram] Excepción al enviar: {e}")
|
||||
|
||||
|
||||
def disparar_monkey_alexa(monkey: str, speech: str = ""):
|
||||
if not config.ALEXA_NOTIFY_SCRIPT or not monkey:
|
||||
return
|
||||
env = os.environ.copy()
|
||||
if config.VOICEMONKEY_TOKEN:
|
||||
env["VOICEMONKEY_TOKEN"] = config.VOICEMONKEY_TOKEN
|
||||
if config.VOICEMONKEY_DEVICE:
|
||||
env["VOICEMONKEY_DEVICE"] = config.VOICEMONKEY_DEVICE
|
||||
cmd = [config.ALEXA_NODE, config.ALEXA_NOTIFY_SCRIPT, "--monkey", monkey]
|
||||
if speech:
|
||||
cmd.append(speech)
|
||||
try:
|
||||
r = subprocess.run(
|
||||
cmd, env=env, timeout=15, capture_output=True, text=True,
|
||||
)
|
||||
if r.returncode != 0:
|
||||
print(f"[Alexa] Error monkey: {r.stderr[:200]}")
|
||||
except Exception as e:
|
||||
print(f"[Alexa] Excepción lanzando monkey: {e}")
|
||||
|
||||
|
||||
def disparar_webhook_alexa(texto: str):
|
||||
if config.ALEXA_NOTIFY_SCRIPT:
|
||||
env = os.environ.copy()
|
||||
|
||||
@@ -139,6 +139,11 @@ def anuncio_en_teles(texto):
|
||||
f"(vol {config.GOOGLE_TV_VOLUMEN})")
|
||||
if _esperar_fin(c):
|
||||
print(f"[Voz] Anuncio terminado en {c.cast_info.friendly_name}")
|
||||
|
||||
if config.ALEXA_APAGAR_TV_MONKEY:
|
||||
print("[Voz] Apagando la tele via Alexa...")
|
||||
from notificador import disparar_monkey_alexa
|
||||
disparar_monkey_alexa(config.ALEXA_APAGAR_TV_MONKEY)
|
||||
if config.GOOGLE_TV_APAGAR:
|
||||
c.quit_app()
|
||||
print(f"[Voz] {c.cast_info.friendly_name} apagada (standby)")
|
||||
|
||||
Reference in New Issue
Block a user