different delimiter and DEBUG and list mics if MIC_NAME=
parent
855a14b985
commit
8ffcb02652
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue