no render mac

master
Bel LaPointe 2025-09-10 11:20:01 -06:00
parent 12dbf12299
commit fffea2ddf0
2 changed files with 229 additions and 181 deletions

2
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "rust-whisper.d/gitea-whisper-rs"]
[submodule "gitea-whisper-rs"]
path = gitea-whisper-rs
url = https://gitea.inhome.blapointe.com/bel/whisper-rs.git

View File

@ -1,7 +1,7 @@
use rust_whisper_lib;
use rust_whisper_baked_lib;
use clap::Parser;
use listen_lib;
use rust_whisper_baked_lib;
use rust_whisper_lib;
use std::thread;
fn main() {
@ -21,8 +21,10 @@ fn wav_channel(flags: rust_whisper_lib::Flags) {
Ok(transcribed) => {
let s = w.step(transcribed.to_string());
println!("{}", s);
},
Err(msg) => { eprintln!("error: {}", msg); },
}
Err(msg) => {
eprintln!("error: {}", msg);
}
};
},
);
@ -30,14 +32,17 @@ fn wav_channel(flags: rust_whisper_lib::Flags) {
fn wav(flags: rust_whisper_lib::Flags, _path: String) {
let mut w = new_destutterer();
rust_whisper_baked_lib::wav(flags,
rust_whisper_baked_lib::wav(
flags,
move |result: Result<rust_whisper_lib::Transcribed, String>| {
match result {
Ok(transcribed) => {
let s = w.step(transcribed.to_string());
println!("{}", s);
},
Err(msg) => { eprintln!("error: {}", msg); },
}
Err(msg) => {
eprintln!("error: {}", msg);
}
};
},
);
@ -56,8 +61,10 @@ fn channel(flags: rust_whisper_lib::Flags) {
Ok(transcribed) => {
let s = w.step(transcribed.to_string());
println!("{}", s);
},
Err(msg) => { eprintln!("error: {}", msg); },
}
Err(msg) => {
eprintln!("error: {}", msg);
}
};
},
recv,
@ -77,11 +84,14 @@ fn channel(flags: rust_whisper_lib::Flags) {
}
eprintln!("found {} devices", i);
} else {
listen_lib::main_with(|data| {
listen_lib::main_with(
|data| {
send.send(data).unwrap();
}, device_name);
}
},
device_name,
);
}
}
None => {
eprintln!("without any device");
listen_lib::main(|data| {
@ -107,7 +117,10 @@ impl Destutterer {
}
let next_words = Words::from_string(next.clone());
let mut n = self.prev.comparable_len().clamp(0, next_words.comparable_len());
let mut n = self
.prev
.comparable_len()
.clamp(0, next_words.comparable_len());
//println!("n={} prev='{:?}' next='{:?}'", n, self.prev.to_comparable_words(), next_words.to_comparable_words());
while n > 0 {
let (prev_s, _) = self.prev.last_n_comparable_to_string(n);
@ -153,13 +166,25 @@ impl Words {
fn last_n_comparable_to_string(&self, n: usize) -> (String, usize) {
let v = self.to_comparable_words();
let v = v[(v.len() - n).clamp(0, v.len())..].to_vec();
return (v.iter().map(|x| x.s.clone().unwrap()).collect::<Vec<String>>().join(" "), v[0].idx)
return (
v.iter()
.map(|x| x.s.clone().unwrap())
.collect::<Vec<String>>()
.join(" "),
v[0].idx,
);
}
fn first_n_comparable_to_string(&self, n: usize) -> (String, usize) {
let v = self.to_comparable_words();
let v = v[0..n.clamp(0, v.len())].to_vec();
return (v.iter().map(|x| x.s.clone().unwrap()).collect::<Vec<String>>().join(" "), v[v.len()-1].idx)
return (
v.iter()
.map(|x| x.s.clone().unwrap())
.collect::<Vec<String>>()
.join(" "),
v[v.len() - 1].idx,
);
}
fn comparable_len(&self) -> usize {
@ -167,7 +192,8 @@ impl Words {
}
fn to_comparable_words(&self) -> Vec<Word> {
self.to_words().iter()
self.to_words()
.iter()
.filter(|x| x.s.is_some())
.map(|x| x.clone())
.collect()
@ -176,9 +202,15 @@ impl Words {
fn to_words(&self) -> Vec<Word> {
let skips = stop_words::get("en");
let stemmer = rust_stemmers::Stemmer::create(rust_stemmers::Algorithm::English);
let strs = self.raw.iter()
let strs = self
.raw
.iter()
.map(|w| w.to_lowercase())
.map(|w| w.chars().filter(|c| c.is_ascii_alphanumeric()).collect::<String>())
.map(|w| {
w.chars()
.filter(|c| c.is_ascii_alphanumeric())
.collect::<String>()
})
.map(|w| stemmer.stem(&w).into_owned())
.collect::<Vec<String>>();
let mut result = vec![];
@ -195,7 +227,8 @@ impl Words {
}
fn to_string(&self) -> String {
self.raw.iter()
self.raw
.iter()
.map(|x| x.clone())
.collect::<Vec<String>>()
.join(" ")
@ -215,22 +248,37 @@ mod tests {
#[test]
fn test_destutterer_stop_words() {
let mut w = new_destutterer();
assert_eq!("welcome to the internet".to_string(), w.step("welcome to the internet".to_string()));
assert_eq!("have a look around".to_string(), w.step("welcome to the a internet; have a look around".to_string()));
assert_eq!(
"welcome to the internet".to_string(),
w.step("welcome to the internet".to_string())
);
assert_eq!(
"have a look around".to_string(),
w.step("welcome to the a internet; have a look around".to_string())
);
}
#[test]
fn test_destutterer_punctuation() {
let mut w = new_destutterer();
assert_eq!("cat, dog. cow? moose!".to_string(), w.step("cat, dog. cow? moose!".to_string()));
assert_eq!("elephant! fez gator".to_string(), w.step("moose, elephant! fez gator".to_string()));
assert_eq!(
"cat, dog. cow? moose!".to_string(),
w.step("cat, dog. cow? moose!".to_string())
);
assert_eq!(
"elephant! fez gator".to_string(),
w.step("moose, elephant! fez gator".to_string())
);
assert_eq!("hij".to_string(), w.step("fez gator hij".to_string()));
}
#[test]
fn test_destutterer_basic() {
let mut w = new_destutterer();
assert_eq!("cat dog cow".to_string(), w.step(" cat dog cow ".to_string()));
assert_eq!(
"cat dog cow".to_string(),
w.step(" cat dog cow ".to_string())
);
assert_eq!("moose".to_string(), w.step(" dog cow moose ".to_string()));
}
}