From 8ffcb02652ec1cea9840cf731cc949f78359f8de Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 26 Mar 2023 09:55:16 -0600 Subject: [PATCH] different delimiter and DEBUG and list mics if MIC_NAME= --- whisper-2023/hotwords.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/whisper-2023/hotwords.py b/whisper-2023/hotwords.py index be73511..aa201d1 100644 --- a/whisper-2023/hotwords.py +++ b/whisper-2023/hotwords.py @@ -60,6 +60,10 @@ class Reader(threading.Thread): def __init__(self, inq, outq): threading.Thread.__init__(self) self.name = environ.get("MIC_NAME", "pulse_monitor") + if not self.name: + for index, name in enumerate(sr.Microphone.list_microphone_names()): + print("[{0}] Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name)) + exit() self.inq = inq self.outq = outq @@ -158,6 +162,8 @@ class Reactor(threading.Thread): def handle(self, text): hotwords = self.load_hotwords() + if environ.get("DEBUG", None): + log(f"seeking {hotwords} in {text}") if not hotwords: self.outq.put(("", text)) return @@ -180,6 +186,8 @@ class Actor(threading.Thread): elif environ.get("URL", ""): self.url = environ["URL"] self.handle = self.handle_url + self.headers = [i.split("=")[:2] for i in environ.get("HEADERS", "").split("//") if i] + log(self.headers) def run(self): log("Actor.run: start") @@ -204,7 +212,15 @@ class Actor(threading.Thread): def handle_url(self, hotword, context): self.handle_stderr(hotword, context) try: - requests.post(self.url, json={"hotword":hotword, "context":context}) + headers = {} + for i in self.headers: + key = i[0] + value = i[1] + value = value.replace("{{hotword}}", hotword) + value = value.replace("{{context}}", context) + headers[key] = value + log("POST", self.url, headers, hotword, context) + requests.post(self.url, json={"hotword":hotword, "context":context}, headers=headers) except Exception as e: log("Actor.handle_url:", e)