Expose WhisperContextParameters and update examples
This commit is contained in:
parent
bd197a36f3
commit
8d462f5dd3
5 changed files with 21 additions and 9 deletions
|
|
@ -4,13 +4,15 @@
|
|||
use hound;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use whisper_rs::{FullParams, SamplingStrategy, WhisperContext};
|
||||
use whisper_rs::{FullParams, SamplingStrategy, WhisperContext, WhisperContextParameters};
|
||||
|
||||
/// Loads a context and model, processes an audio file, and prints the resulting transcript to stdout.
|
||||
fn main() -> Result<(), &'static str> {
|
||||
// Load a context and model.
|
||||
let ctx = WhisperContext::new("example/path/to/model/whisper.cpp/models/ggml-base.en.bin")
|
||||
.expect("failed to load model");
|
||||
let ctx = WhisperContext::new_with_params(
|
||||
"example/path/to/model/whisper.cpp/models/ggml-base.en.bin",
|
||||
WhisperContextParameters::default()
|
||||
).expect("failed to load model");
|
||||
// Create a state
|
||||
let mut state = ctx.create_state().expect("failed to create key");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
#![allow(clippy::uninlined_format_args)]
|
||||
|
||||
use whisper_rs::{FullParams, SamplingStrategy, WhisperContext};
|
||||
use whisper_rs::{FullParams, SamplingStrategy, WhisperContext, WhisperContextParameters};
|
||||
|
||||
// note that running this example will not do anything, as it is just a
|
||||
// demonstration of how to use the library, and actual usage requires
|
||||
// more dependencies than the base library.
|
||||
pub fn usage() -> Result<(), &'static str> {
|
||||
// load a context and model
|
||||
let ctx = WhisperContext::new("path/to/model").expect("failed to load model");
|
||||
let ctx = WhisperContext::new_with_params(
|
||||
"path/to/model",
|
||||
WhisperContextParameters::default()
|
||||
).expect("failed to load model");
|
||||
// make a state
|
||||
let mut state = ctx.create_state().expect("failed to create state");
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use hound::{SampleFormat, WavReader};
|
||||
use std::path::Path;
|
||||
use whisper_rs::{FullParams, SamplingStrategy, WhisperContext};
|
||||
use whisper_rs::{FullParams, SamplingStrategy, WhisperContext, WhisperContextParameters};
|
||||
|
||||
fn parse_wav_file(path: &Path) -> Vec<i16> {
|
||||
let reader = WavReader::open(path).expect("failed to read file");
|
||||
|
|
@ -45,7 +45,10 @@ fn main() {
|
|||
let original_samples = parse_wav_file(audio_path);
|
||||
let samples = whisper_rs::convert_integer_to_float_audio(&original_samples);
|
||||
|
||||
let ctx = WhisperContext::new(&whisper_path.to_string_lossy()).expect("failed to open model");
|
||||
let ctx = WhisperContext::new_with_params(
|
||||
&whisper_path.to_string_lossy(),
|
||||
WhisperContextParameters::default()
|
||||
).expect("failed to open model");
|
||||
let mut state = ctx.create_state().expect("failed to create key");
|
||||
let mut params = FullParams::new(SamplingStrategy::default());
|
||||
params.set_progress_callback_safe(|progress| println!("Progress callback: {}%", progress));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue