migrate state method into state object

This commit is contained in:
Yuniru Yuni 2023-04-30 08:28:46 +09:00
parent 0fe0a87a09
commit ef4b9f0630
No known key found for this signature in database
GPG key ID: 33E3309A80C571CD
5 changed files with 539 additions and 581 deletions

View file

@ -12,7 +12,7 @@ fn main() -> Result<(), &'static str> {
let ctx = WhisperContext::new("example/path/to/model/whisper.cpp/models/ggml-base.en.bin")
.expect("failed to load model");
// Create a state
let state = ctx.create_state().expect("failed to create key");
let mut state = ctx.create_state().expect("failed to create key");
// Create a params object for running the model.
// The number of past samples to consider defaults to 0.
@ -63,26 +63,25 @@ fn main() -> Result<(), &'static str> {
}
// Run the model.
ctx.full(&state, params, &audio[..])
.expect("failed to run model");
state.full(params, &audio[..]).expect("failed to run model");
// Create a file to write the transcript to.
let mut file = File::create("transcript.txt").expect("failed to create file");
// Iterate through the segments of the transcript.
let num_segments = ctx
.full_n_segments(&state)
let num_segments = state
.full_n_segments()
.expect("failed to get number of segments");
for i in 0..num_segments {
// Get the transcribed text and timestamps for the current segment.
let segment = ctx
.full_get_segment_text(&state, i)
let segment = state
.full_get_segment_text(i)
.expect("failed to get segment");
let start_timestamp = ctx
.full_get_segment_t0(&state, i)
let start_timestamp = state
.full_get_segment_t0(i)
.expect("failed to get start timestamp");
let end_timestamp = ctx
.full_get_segment_t1(&state, i)
let end_timestamp = state
.full_get_segment_t1(i)
.expect("failed to get end timestamp");
// Print the segment to stdout.