Compare commits
12 Commits
v0.0.2
...
247edd2ced
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
247edd2ced | ||
|
|
edd94aef72 | ||
|
|
b4d3e5a27c | ||
|
|
a1436e3bd2 | ||
|
|
410769b8c6 | ||
|
|
5869016de6 | ||
|
|
0955f6c0c0 | ||
|
|
242f4407df | ||
|
|
814a8ae2f3 | ||
|
|
7c369e72d4 | ||
|
|
0aff4f556b | ||
|
|
88bf54d022 |
@@ -47,7 +47,7 @@ class Reader(threading.Thread):
|
|||||||
self.name = os.environ.get("MIC_NAME", "pulse_monitor")
|
self.name = os.environ.get("MIC_NAME", "pulse_monitor")
|
||||||
if not self.name:
|
if not self.name:
|
||||||
for index, name in enumerate(sr.Microphone.list_microphone_names()):
|
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))
|
log("[{0}] Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
|
||||||
exit()
|
exit()
|
||||||
self.inq = inq
|
self.inq = inq
|
||||||
self.outq = outq
|
self.outq = outq
|
||||||
@@ -136,14 +136,19 @@ class Parser(threading.Thread):
|
|||||||
p = "/tmp/whisper-cpp.wav"
|
p = "/tmp/whisper-cpp.wav"
|
||||||
with open("/tmp/whisper-cpp.wav", "wb") as f:
|
with open("/tmp/whisper-cpp.wav", "wb") as f:
|
||||||
f.write(wav)
|
f.write(wav)
|
||||||
proc = subprocess.run(f"MODEL=./models/ggml-{os.environ.get('MODEL','tiny.en')}.bin WAV={p} P=2 rust-whisper", capture_output=True, shell=True)
|
proc = subprocess.run(f"MODEL=./models/ggml-{os.environ.get('MODEL','tiny.en')}.bin WAV={p} P={os.environ.get('P', '2')} rust-whisper", capture_output=True, shell=True)
|
||||||
result = proc.stdout.decode().strip()
|
result = proc.stdout.decode().strip()
|
||||||
if os.environ.get("DEBUG", None):
|
if os.environ.get("DEBUG", None):
|
||||||
log("stderr:", proc.stderr.decode().strip())
|
log("stderr:", proc.stderr.decode().strip())
|
||||||
log("raw transcript:", result)
|
log("raw transcript:", result)
|
||||||
result = result.replace(">>", "")
|
result = result.replace(">>", "")
|
||||||
result = "".join([i.split("]")[-1] for i in result.split("[")[0]])
|
for pair in [
|
||||||
result = "".join([i.split(")")[-1] for i in result.split("(")[0]])
|
("[", "]"),
|
||||||
|
("(", ")"),
|
||||||
|
("<", ">"),
|
||||||
|
("*", "*"),
|
||||||
|
]:
|
||||||
|
result = "".join([i.split(pair[1])[-1] for i in result.split(pair[0])[0]])
|
||||||
if os.environ.get("DEBUG", None):
|
if os.environ.get("DEBUG", None):
|
||||||
log("annotation-free transcript:", result)
|
log("annotation-free transcript:", result)
|
||||||
return result
|
return result
|
||||||
@@ -180,6 +185,8 @@ def _load_dot_notation(v, items):
|
|||||||
else:
|
else:
|
||||||
result.append(subresult)
|
result.append(subresult)
|
||||||
return result
|
return result
|
||||||
|
elif k == "KEYS":
|
||||||
|
v = [k for k in v]
|
||||||
else:
|
else:
|
||||||
if isinstance(v, list):
|
if isinstance(v, list):
|
||||||
v = v[int(k)]
|
v = v[int(k)]
|
||||||
@@ -224,8 +231,15 @@ class Reactor(threading.Thread):
|
|||||||
def load_hotwords_in_yaml_file():
|
def load_hotwords_in_yaml_file():
|
||||||
with open(p.split("@")[0], "r") as f:
|
with open(p.split("@")[0], "r") as f:
|
||||||
v = yaml.safe_load(f)
|
v = yaml.safe_load(f)
|
||||||
v = load_dot_notation(v, p.split("@")[-1])
|
if os.environ.get("DEBUG", None):
|
||||||
return ["".join(i.strip().lower().split()) for i in v if i]
|
log(f'opened {p.split("@")[0]} and got {v}')
|
||||||
|
result = []
|
||||||
|
for to_find in [i for i in p.split("@")[-1].split(",") if i]:
|
||||||
|
if os.environ.get("DEBUG", None):
|
||||||
|
log(f'finding {to_find} in {v}')
|
||||||
|
v2 = load_dot_notation(v, to_find)
|
||||||
|
result.extend(["".join(i.strip().lower().split()) for i in v2 if i])
|
||||||
|
return result
|
||||||
load_hotwords_in_yaml_file()
|
load_hotwords_in_yaml_file()
|
||||||
return load_hotwords_in_yaml_file
|
return load_hotwords_in_yaml_file
|
||||||
else:
|
else:
|
||||||
@@ -254,13 +268,23 @@ class Reactor(threading.Thread):
|
|||||||
log("Reactor.run: stop")
|
log("Reactor.run: stop")
|
||||||
|
|
||||||
def handle(self, text):
|
def handle(self, text):
|
||||||
|
try:
|
||||||
|
self._handle(text)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _handle(self, text):
|
||||||
hotwords = self.load_hotwords()
|
hotwords = self.load_hotwords()
|
||||||
if os.environ.get("DEBUG", None):
|
if os.environ.get("DEBUG", None):
|
||||||
log(f"seeking {hotwords} in {text}")
|
log(f"seeking {hotwords} in {text}. $HOTWORDS={os.environ.get('HOTWORDS', None)}")
|
||||||
if not hotwords:
|
if not hotwords:
|
||||||
if not os.environ.get("HOTWORDS", None):
|
if not os.environ.get("HOTWORDS", None):
|
||||||
print(text)
|
if os.environ.get("DEBUG", None):
|
||||||
|
log(f"HOTWORDS is False; {text}")
|
||||||
|
print(text, flush=True)
|
||||||
else:
|
else:
|
||||||
|
if os.environ.get("DEBUG", None):
|
||||||
|
log(f"HOTWORDS is True; {text}")
|
||||||
log(text)
|
log(text)
|
||||||
return
|
return
|
||||||
cleantext = "".join([i for i in "".join(text.lower().split()) if i.isalpha()])
|
cleantext = "".join([i for i in "".join(text.lower().split()) if i.isalpha()])
|
||||||
@@ -300,7 +324,7 @@ class Actor(threading.Thread):
|
|||||||
|
|
||||||
def handle_stdout(self, hotword, context):
|
def handle_stdout(self, hotword, context):
|
||||||
log(context)
|
log(context)
|
||||||
print(hotword)
|
print(hotword, flush=True)
|
||||||
|
|
||||||
def handle_signal(self, hotword, context):
|
def handle_signal(self, hotword, context):
|
||||||
self.handle_stderr(hotword, context)
|
self.handle_stderr(hotword, context)
|
||||||
@@ -319,9 +343,12 @@ class Actor(threading.Thread):
|
|||||||
body = self.body
|
body = self.body
|
||||||
body = body.replace("{{hotword}}", hotword)
|
body = body.replace("{{hotword}}", hotword)
|
||||||
body = body.replace("{{context}}", context)
|
body = body.replace("{{context}}", context)
|
||||||
|
url = self.url
|
||||||
|
url = url.replace("{{hotword}}", hotword)
|
||||||
|
url = url.replace("{{context}}", context)
|
||||||
if os.environ.get("DEBUG", "") :
|
if os.environ.get("DEBUG", "") :
|
||||||
log("POST", self.url, headers, body)
|
log("POST", url, headers, body)
|
||||||
requests.post(self.url, headers=headers, data=body)
|
requests.post(url, headers=headers, data=body)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log("Actor.handle_url:", e)
|
log("Actor.handle_url:", e)
|
||||||
|
|
||||||
|
|||||||
2
rust-whisper.d/transcript.sh
Normal file
2
rust-whisper.d/transcript.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
echo "pkill -9 -f hotwords.py; MIC_TIMEOUT=30 MODEL=small.en P=4 DEBUG=true HOTWORDS= python3 ./hotwords.py | tee -a $HOME/Sync/drawful/DnD/bdoob/__log.d/$(date +%Y.%m.%d).transcript.txt"
|
||||||
|
echo "pkill -9 -f hotwords.py; MIC_TIMEOUT=30 MODEL=small.en P=4 DEBUG=true HOTWORDS= python3 ./hotwords.py | tee -a $HOME/Sync/drawful/DnD/nessira.d/_log.d/$(date +%Y.%m.%d).transcript.txt"
|
||||||
Reference in New Issue
Block a user