found burn depends on zstd that doesnt wasm

master
Bel LaPointe 2023-12-21 22:13:23 -05:00
parent d63d05505c
commit 1c9d646a50
6 changed files with 7282 additions and 636 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -232,29 +232,6 @@ dependencies = [
"serde",
]
[[package]]
name = "bindgen"
version = "0.68.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078"
dependencies = [
"bitflags 2.3.3",
"cexpr",
"clang-sys",
"lazy_static",
"lazycell",
"log",
"peeking_take_while",
"prettyplease",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"syn 2.0.32",
"which",
]
[[package]]
name = "bit-set"
version = "0.5.3"
@ -552,15 +529,6 @@ dependencies = [
"jobserver",
]
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom 7.1.3",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
@ -597,17 +565,6 @@ dependencies = [
"inout",
]
[[package]]
name = "clang-sys"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "clap"
version = "2.34.0"
@ -663,15 +620,6 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "cmake"
version = "0.1.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130"
dependencies = [
"cc",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
@ -1294,12 +1242,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]]
name = "futures-channel"
version = "0.3.28"
@ -1939,12 +1881,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "lebe"
version = "0.5.2"
@ -2541,12 +2477,6 @@ dependencies = [
"sha2",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "percent-encoding"
version = "2.3.0"
@ -2622,16 +2552,6 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "prettyplease"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d"
dependencies = [
"proc-macro2",
"syn 2.0.32",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
@ -2994,7 +2914,6 @@ dependencies = [
"clap 4.4.11",
"wav",
"whisper",
"whisper-rs",
]
[[package]]
@ -3254,12 +3173,6 @@ dependencies = [
"digest",
]
[[package]]
name = "shlex"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
[[package]]
name = "signal-hook"
version = "0.3.17"
@ -4167,17 +4080,6 @@ dependencies = [
"web-sys",
]
[[package]]
name = "which"
version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
dependencies = [
"either",
"libc",
"once_cell",
]
[[package]]
name = "whisper"
version = "0.1.0"
@ -4195,23 +4097,6 @@ dependencies = [
"tokenizers",
]
[[package]]
name = "whisper-rs"
version = "0.8.0"
dependencies = [
"whisper-rs-sys",
]
[[package]]
name = "whisper-rs-sys"
version = "0.7.3"
dependencies = [
"bindgen",
"cfg-if 1.0.0",
"cmake",
"fs_extra",
]
[[package]]
name = "widestring"
version = "1.0.2"

View File

@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
whisper-rs = { path = "../gitea-whisper-rs", version = "0.8.0" }
whisper = { path = "../whisper-burn", version = "0.1.0", features = ["wgpu-backend"] }
clap = { version = "4.4.10", features = ["derive"] }
wav = "1"

View File

@ -1,4 +1,3 @@
use whisper_rs::{WhisperContext, FullParams, SamplingStrategy, WhisperError};
use clap::Parser;
use std::thread;
use std::fs::File;
@ -61,7 +60,13 @@ fn f32_from_wav_file(path: &String) -> Result<Vec<f32>, String> {
return Err("!= 16_000 hz".to_string());
}
match data.as_sixteen() {
Some(data16) => Ok(whisper_rs::convert_integer_to_float_audio(&data16)),
Some(data16) => {
let mut floats = Vec::with_capacity(data16.len());
for sample in data16 {
floats.push(*sample as f32 / 32768.0);
}
Ok(floats)
},
None => Err(format!("couldnt translate wav to 16s")),
}
}
@ -113,7 +118,7 @@ struct Service {
}
fn new_service<F>(model_path: Option<String>, model_buffer: Option<Vec<u8>>, threads: i32, stream_head: f32, stream_tail: f32, handler_fn: F) -> Result<Service, String> where F: FnMut(Result<Transcribed, String>) + Send + 'static {
match new_engine(model_path, model_buffer, threads) {
match new_engine_2() {
Ok(engine) => {
let mut whisper = new_whisper_impl(engine, stream_head, stream_tail, handler_fn);
let (send, recv) = std::sync::mpsc::sync_channel(100);
@ -147,13 +152,13 @@ impl Service {
}
struct Impl {
engine: Engine,
engine: Engine2,
stream_head: f32,
stream_tail: f32,
handler_fn: Option<Box<dyn FnMut(Result<Transcribed, String>) + Send + 'static>>
}
fn new_whisper_impl<F>(engine: Engine, stream_head: f32, stream_tail: f32, handler_fn: F) -> Impl where F: FnMut(Result<Transcribed, String>) + Send + 'static {
fn new_whisper_impl<F>(engine: Engine2, stream_head: f32, stream_tail: f32, handler_fn: F) -> Impl where F: FnMut(Result<Transcribed, String>) + Send + 'static {
Impl {
engine: engine,
stream_head: stream_head,
@ -205,58 +210,6 @@ impl Impl {
}
}
struct Engine {
ctx: WhisperContext,
threads: i32,
}
fn new_engine(model_path: Option<String>, model_buffer: Option<Vec<u8>>, threads: i32) -> Result<Engine, String> {
let whisper_context_result = match model_path {
Some(model_path) => WhisperContext::new(&model_path),
None => WhisperContext::new_from_buffer(&model_buffer.unwrap()),
};
match whisper_context_result {
Ok(ctx) => Ok(Engine{ctx: ctx, threads: threads}),
Err(msg) => Err(format!("failed to load model: {}", msg)),
}
}
impl Engine {
fn transcribe(&self, data: &Vec<f32>) -> Result<Transcribed, String> {
match self._transcribe(data) {
Ok(transcribed) => Ok(transcribed),
Err(msg) => Err(format!("{}", msg)),
}
}
fn _transcribe(&self, data: &Vec<f32>) -> Result<Transcribed, WhisperError> {
let mut params = FullParams::new(SamplingStrategy::Greedy { best_of: 0 });
params.set_no_context(true);
params.set_n_threads(self.threads);
params.set_translate(false);
params.set_detect_language(false);
params.set_language(Some("en"));
params.set_print_special(false);
params.set_print_progress(false);
params.set_print_realtime(false);
params.set_print_timestamps(false);
let mut state = self.ctx.create_state()?;
state.full(params, &data[..])?;
let mut result = new_whispered();
let num_segments = state.full_n_segments()?;
for i in 0..num_segments {
let data = state.full_get_segment_text(i)?;
let start = state.full_get_segment_t0(i)?;
let stop = state.full_get_segment_t1(i)?;
result.push(data, start, stop);
}
Ok(result)
}
}
struct Engine2 {
}
@ -346,29 +299,6 @@ impl Transcribed {
mod tests {
use super::*;
#[test]
fn test_transcribe_tiny_jfk_wav_whisper_rs() {
wav(
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,
stream_device: None,
},
| 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.");
},
"../gitea-whisper-rs/sys/whisper.cpp/bindings/go/samples/jfk.wav".to_string(),
);
}
#[test]
fn test_transcribe_tiny_jfk_wav_candle() {
let wav_path = "../gitea-whisper-rs/sys/whisper.cpp/bindings/go/samples/jfk.wav".to_string();

@ -1 +0,0 @@
Subproject commit 0ee20fbc805d595f14e637503c295f9dc4fa2eb9