3 Commits

Author SHA1 Message Date
Bel LaPointe
26f3ccad37 make a unittest 2023-12-20 09:01:06 -05:00
Bel LaPointe
27562e6599 wasm dead in the water because no libc 2023-12-20 07:30:27 -05:00
Bel LaPointe
6502402fca wasm-friendly args 2023-12-20 06:47:25 -05:00
3 changed files with 51 additions and 6 deletions

View File

@@ -3,7 +3,8 @@ name = "rust-whisper-baked-lib-wasm"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]
[dependencies]
rust-whisper-lib = { path = "../rust-whisper-lib" }

View File

@@ -2,16 +2,34 @@ use wasm_bindgen::prelude::*;
use rust_whisper_lib;
use rust_whisper_baked_lib;
#[wasm_bindgen]
extern {
pub fn whisper_on_success(s: String);
pub fn whisper_on_error(s: String);
}
#[wasm_bindgen]
pub fn listen(
flags: rust_whisper_lib::Flags,
on_success: fn(String),
on_error: fn(String),
stream_step: Option<u64>,
stream_retain: Option<f32>,
stream_head: Option<f32>,
stream_tail: Option<f32>,
) {
let flags = rust_whisper_lib::Flags {
model_path: None,
model_buffer: None,
threads: 4,
stream_step: stream_step.unwrap_or(5),
stream_retain: stream_retain.unwrap_or(1.0),
stream_head: stream_head.unwrap_or(0.5),
stream_tail: stream_tail.unwrap_or(0.5),
wav: None,
debug: false,
};
rust_whisper_baked_lib::main(flags, |result| {
match result {
Ok(msg) => on_success(msg.to_string()),
Err(msg) => on_error(msg),
Ok(msg) => whisper_on_success(msg.to_string()),
Err(msg) => whisper_on_error(msg),
};
});
}

View File

@@ -376,3 +376,29 @@ impl Listener {
stream.pause().unwrap();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_transcribe_tiny_jfk_wav() {
main(
Flags {
model_path: None,
model_buffer: Some(include_bytes!("../../models/ggml-tiny.en.bin").to_vec()),
threads: 8,
stream_step: 0,
stream_retain: 0.0,
stream_head: 0.0,
stream_tail: 0.0,
wav: Some("../gitea-whisper-rs/sys/whisper.cpp/bindings/go/samples/jfk.wav".to_string()),
debug: false,
},
| result | {
assert!(result.is_ok());
assert_eq!(result.unwrap().to_string(), " And so my fellow Americans ask not what your country can do for you ask what you can do for your country.");
},
);
}
}