RUST RUNS WOO
parent
2699d73c9c
commit
8a71756b89
|
|
@ -172,6 +172,12 @@ version = "0.6.29"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "riff"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9b1a3d5f46d53f4a3478e2be4a5a5ce5108ea58b100dcd139830eae7f79a3a1"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
|
|
@ -201,6 +207,15 @@ version = "1.0.8"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||
|
||||
[[package]]
|
||||
name = "wav"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a65e199c799848b4f997072aa4d673c034f80f40191f97fe2f0a23f410be1609"
|
||||
dependencies = [
|
||||
"riff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.4.0"
|
||||
|
|
@ -216,6 +231,7 @@ dependencies = [
|
|||
name = "whisper-cpp-er"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"wav",
|
||||
"whisper-rs",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -7,3 +7,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
whisper-rs = "0.5"
|
||||
wav = "1"
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
use whisper_rs::{WhisperContext, FullParams, SamplingStrategy};
|
||||
use std::io::Read;
|
||||
|
||||
fn main() {
|
||||
let mut ctx = WhisperContext::new("../models/ggml-tiny.en.bin").expect("failed to load model");
|
||||
|
||||
// create a params object
|
||||
let params = FullParams::new(SamplingStrategy::Greedy { best_of: 0 });
|
||||
let mut params = FullParams::new(SamplingStrategy::Greedy { best_of: 0 });
|
||||
params.set_n_threads(4);
|
||||
params.set_translate(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);
|
||||
|
||||
// assume we have a buffer of audio data
|
||||
// here we'll make a fake one, floating point samples, 32 bit, 16KHz, mono
|
||||
//let audio_data = vec![0_f32; 16000 * 2];
|
||||
let mut audio_data = Vec::new();
|
||||
let mut input = std::io::BufReader::new(std::fs::File::open("../git.d/samples/jfk.wav").expect("cannot open jfk.wav"));
|
||||
loop {
|
||||
let mut buff = [0u8; std::mem::size_of::<f32>()];
|
||||
let res = input.read_exact(&mut buff);
|
||||
match res {
|
||||
Err(_) => break,
|
||||
_ => {},
|
||||
};
|
||||
audio_data.push(f32::from_le_bytes(buff));
|
||||
}
|
||||
let (header, data) = wav::read(&mut std::fs::File::open("../git.d/samples/jfk.wav").expect("failed to open .wav")).expect("failed to decode .wav");
|
||||
assert!(header.channel_count == 1);
|
||||
assert!(header.sampling_rate == 16000);
|
||||
let data16 = data.as_sixteen().expect("wav is not 32bit floats");
|
||||
let audio_data = &whisper_rs::convert_integer_to_float_audio(&data16);
|
||||
|
||||
// now we can run the model
|
||||
ctx.full(params, &audio_data[..])
|
||||
|
|
|
|||
Loading…
Reference in New Issue