18 Commits

Author SHA1 Message Date
Bel LaPointe
50058037eb Revert "try rollback to whisper-rs5 to avoid gpu in whispercpp but no luck"
This reverts commit a483aaf25c.
2023-11-08 11:35:31 -07:00
Bel LaPointe
a483aaf25c try rollback to whisper-rs5 to avoid gpu in whispercpp but no luck 2023-11-08 11:35:29 -07:00
Bel LaPointe
be7d85f85e confirmed whisper.cpp works with distill iff no gpu 2023-11-08 11:29:50 -07:00
Bel LaPointe
60d38c4d5c update distil.sh 2023-11-08 10:58:58 -07:00
Bel LaPointe
e3a7628acf try distil-whisper 2023-11-08 10:22:30 -07:00
Bel LaPointe
91c7791860 up whisper-rs to 0.8.0 2023-11-08 09:25:00 -07:00
bel
247edd2ced more trans 2023-07-15 19:05:00 -06:00
bel
edd94aef72 catch 2023-07-05 22:36:07 -06:00
bel
b4d3e5a27c HOTWORDS yaml @ can have comma delimited and KEYS 2023-04-19 18:24:07 -06:00
bel
a1436e3bd2 revise 2023-04-12 19:37:43 -06:00
bel
410769b8c6 tr 2023-04-12 19:26:03 -06:00
bel
5869016de6 tr 2023-04-12 19:16:07 -06:00
bel
0955f6c0c0 oof 2023-04-12 19:15:32 -06:00
bel
242f4407df script 2023-04-12 18:50:49 -06:00
bel
814a8ae2f3 typo 2023-04-08 22:23:20 -06:00
bel
7c369e72d4 delimiters 2023-04-08 22:22:22 -06:00
bel
0aff4f556b one more 2023-04-08 20:05:03 -06:00
bel
88bf54d022 url replaces hotword,context too 2023-04-02 10:48:41 -06:00
7 changed files with 86 additions and 24 deletions

View File

@@ -261,20 +261,21 @@ dependencies = [
[[package]] [[package]]
name = "whisper-rs" name = "whisper-rs"
version = "0.5.0" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7e1b9b003aa3285a0e4469219566266aa1d51ced1be38587251a4f713a1677" checksum = "2c950fb18ad556b053ba615b88fd4d01ed6020be740c3371eb0fc4aec64a0639"
dependencies = [ dependencies = [
"whisper-rs-sys", "whisper-rs-sys",
] ]
[[package]] [[package]]
name = "whisper-rs-sys" name = "whisper-rs-sys"
version = "0.3.1" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97a389dc665c7354ba6b1982850d4ba05b862907e535708ebdec92cbd9c599e8" checksum = "094a5bd86f6f52562bbc74c28f27cd80197e54656cfb7213cf4ba37b5246cc9e"
dependencies = [ dependencies = [
"bindgen", "bindgen",
"cfg-if",
] ]
[[package]] [[package]]

View File

@@ -6,6 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
whisper-rs = "0.5" whisper-rs = "0.8.0"
wav = "1" wav = "1"
tokio = "1.27" tokio = "1.27"

View File

@@ -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)

View File

@@ -0,0 +1,33 @@
#! /bin/bash
set -ueo pipefail
cd "$(dirname "$(realpath "$BASH_SOURCE")")"
if git lfs 2>&1 | grep not.a.git; then
brew install git-lfs
fi
echo "https://github.com/ggerganov/whisper.cpp/pull/1424" >&2
if ! test -d ./whisper; then
git clone https://github.com/openai/whisper
fi
if ! test -d ./whisper.cpp; then
git clone https://github.com/ggerganov/whisper.cpp
fi
cd ./whisper.cpp/models
for name in distil-medium.en; do # distil-large-v2
if ! test -f ../../ggml-$name.bin; then
if ! test -d ./$name; then
git clone https://huggingface.co/distil-whisper/$name
fi
cd ./$name
git lfs install
git lfs pull --include $(ls ggml*.en.bin | grep -v fp32)
git lfs install
mv $(ls ggml*.en.bin | grep -v fp32) ../../ggml-$name.bin
cd ..
rm -rf ./$name
fi
done

View File

@@ -1,10 +1,9 @@
#!/bin/bash #!/bin/bash
src="https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml" src="https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml"
d="${1:-"$PWD"/models}" cd "$(dirname "$(realpath "$BASH_SOURCE")")"
mkdir -p "$d"
# Whisper models # Whisper models
for model in "tiny.en" "base.en" "small.en" "medium.en"; do for model in "tiny.en" "base.en" "small.en" "medium.en"; do
test -f "$d"/ggml-$model.bin || wget --quiet --show-progress -O "$d"/ggml-$model.bin "$src-$model.bin" test -f ./ggml-$model.bin || wget --quiet --show-progress -O ./ggml-$model.bin "$src-$model.bin"
done done

View File

@@ -1,9 +1,10 @@
use whisper_rs::{WhisperContext, FullParams, SamplingStrategy}; use whisper_rs::{WhisperContext, FullParams, SamplingStrategy};
fn main() { fn main() {
let mut ctx = WhisperContext::new( let ctx = WhisperContext::new(
&std::env::var("MODEL").unwrap_or(String::from("../models/ggml-tiny.en.bin")) &std::env::var("MODEL").unwrap_or(String::from("../models/ggml-tiny.en.bin"))
).expect("failed to load model"); ).expect("failed to load model");
let mut state = ctx.create_state().expect("failed to create state");
// create a params object // create a params object
let mut params = FullParams::new(SamplingStrategy::Greedy { best_of: 0 }); let mut params = FullParams::new(SamplingStrategy::Greedy { best_of: 0 });
@@ -25,12 +26,11 @@ fn main() {
let data16 = data.as_sixteen().expect("wav is not 32bit floats"); let data16 = data.as_sixteen().expect("wav is not 32bit floats");
let audio_data = &whisper_rs::convert_integer_to_float_audio(&data16); let audio_data = &whisper_rs::convert_integer_to_float_audio(&data16);
ctx.full(params, &audio_data[..]) state.full(params, &audio_data[..]).expect("failed to run model");
.expect("failed to run model");
let num_segments = ctx.full_n_segments(); let num_segments = state.full_n_segments().expect("failed to get number of segments");
for i in 0..num_segments { for i in 0..num_segments {
let segment = ctx.full_get_segment_text(i).expect("failed to get segment"); let segment = state.full_get_segment_text(i).expect("failed to get segment");
print!("{} ", segment); print!("{} ", segment);
} }
println!(""); println!("");

View 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"