44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
use wasm_bindgen::prelude::*;
|
|
use rust_whisper_lib;
|
|
use rust_whisper_baked_lib;
|
|
|
|
#[wasm_bindgen]
|
|
extern {
|
|
pub fn whisper_data() -> Vec<f32>;
|
|
pub fn whisper_on_success(s: String);
|
|
pub fn whisper_on_error(s: String);
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
pub fn new_transcriber(
|
|
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,
|
|
stream_device: None,
|
|
};
|
|
let (send, recv) = std::sync::mpsc::sync_channel(100);
|
|
rust_whisper_baked_lib::channel(flags, |result| {
|
|
match result {
|
|
Ok(msg) => whisper_on_success(msg.to_string()),
|
|
Err(msg) => whisper_on_error(msg),
|
|
};
|
|
}, recv);
|
|
loop {
|
|
let data = whisper_data();
|
|
send.send(data).unwrap();
|
|
}
|
|
}
|
|
|