different delimiter and DEBUG and list mics if MIC_NAME=

master
bel 2023-03-26 09:55:16 -06:00
parent 855a14b985
commit 8ffcb02652
1 changed files with 17 additions and 1 deletions

View File

@ -60,6 +60,10 @@ class Reader(threading.Thread):
def __init__(self, inq, outq): def __init__(self, inq, outq):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.name = environ.get("MIC_NAME", "pulse_monitor") 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.inq = inq
self.outq = outq self.outq = outq
@ -158,6 +162,8 @@ class Reactor(threading.Thread):
def handle(self, text): def handle(self, text):
hotwords = self.load_hotwords() hotwords = self.load_hotwords()
if environ.get("DEBUG", None):
log(f"seeking {hotwords} in {text}")
if not hotwords: if not hotwords:
self.outq.put(("", text)) self.outq.put(("", text))
return return
@ -180,6 +186,8 @@ class Actor(threading.Thread):
elif environ.get("URL", ""): elif environ.get("URL", ""):
self.url = environ["URL"] self.url = environ["URL"]
self.handle = self.handle_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): def run(self):
log("Actor.run: start") log("Actor.run: start")
@ -204,7 +212,15 @@ class Actor(threading.Thread):
def handle_url(self, hotword, context): def handle_url(self, hotword, context):
self.handle_stderr(hotword, context) self.handle_stderr(hotword, context)
try: 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: except Exception as e:
log("Actor.handle_url:", e) log("Actor.handle_url:", e)