From 8d608c747057c4ca74dbaba326245d9113d85841 Mon Sep 17 00:00:00 2001 From: bel Date: Sat, 25 Mar 2023 21:38:53 -0600 Subject: [PATCH] hotwords via $HOTWORDS actually less broken --- whisper-2023/hotwords.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/whisper-2023/hotwords.py b/whisper-2023/hotwords.py index 714b461..f7e9d4d 100644 --- a/whisper-2023/hotwords.py +++ b/whisper-2023/hotwords.py @@ -104,13 +104,15 @@ class Reactor(threading.Thread): threading.Thread.__init__(self) self.inq = inq self.outq = outq - self.load_hotwords = Reactor.new_load_hotwords - self.load_hotwords() + self.load_hotwords = Reactor.new_load_hotwords() + [i for i in self.load_hotwords()] def new_load_hotwords(): - p = environ.get("REACTOR_HOTWORDS", None) + p = environ.get("HOTWORDS", None) if not p: - return lambda: [] + def load_nothing(): + return [] + return load_nothing try: def load_hotwords_in_file(): @@ -136,7 +138,14 @@ class Reactor(threading.Thread): def handle(self, text): hotwords = self.load_hotwords() - print(text) + if not hotwords: + self.outq.put(text) + return + cleantext = "".join([i for i in "".join(text.lower().split()) if i.isalpha()]) + for i in hotwords: + if i in cleantext: + log("hotword", i, "in", text, "as", cleantext) + self.outq.put(i) class Actor(threading.Thread): def __init__(self, inq):