Compare commits
3 Commits
da60e92a8b
...
26f3ccad37
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26f3ccad37 | ||
|
|
27562e6599 | ||
|
|
6502402fca |
@@ -3,7 +3,8 @@ name = "rust-whisper-baked-lib-wasm"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rust-whisper-lib = { path = "../rust-whisper-lib" }
|
rust-whisper-lib = { path = "../rust-whisper-lib" }
|
||||||
|
|||||||
@@ -2,16 +2,34 @@ use wasm_bindgen::prelude::*;
|
|||||||
use rust_whisper_lib;
|
use rust_whisper_lib;
|
||||||
use rust_whisper_baked_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]
|
#[wasm_bindgen]
|
||||||
pub fn listen(
|
pub fn listen(
|
||||||
flags: rust_whisper_lib::Flags,
|
stream_step: Option<u64>,
|
||||||
on_success: fn(String),
|
stream_retain: Option<f32>,
|
||||||
on_error: fn(String),
|
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| {
|
rust_whisper_baked_lib::main(flags, |result| {
|
||||||
match result {
|
match result {
|
||||||
Ok(msg) => on_success(msg.to_string()),
|
Ok(msg) => whisper_on_success(msg.to_string()),
|
||||||
Err(msg) => on_error(msg),
|
Err(msg) => whisper_on_error(msg),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -376,3 +376,29 @@ impl Listener {
|
|||||||
stream.pause().unwrap();
|
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.");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user