#[path = "common/mod.rs"]
mod common;
use transcribe_cpp::{CommitPolicy, Model, RunOptions, StreamOptions, StreamState};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut args = std::env::args().skip(1);
let (Some(model_path), Some(audio_path)) = (
common::streaming_model_path(args.next().as_deref()),
common::audio_path(args.next().as_deref()),
) else {
eprintln!(
"skip streaming: streaming model/audio not found \
(set TRANSCRIBE_SMOKE_STREAMING_MODEL / _AUDIO)"
);
return Ok(());
};
let pcm = common::load_wav(&audio_path);
let model = Model::load(&model_path)?;
if !model.capabilities().supports_streaming {
eprintln!("{} does not support streaming", model.arch());
return Ok(());
}
let mut session = model.session()?;
let opts = StreamOptions {
commit_policy: CommitPolicy::Auto,
..Default::default()
};
let mut stream = session.stream(&RunOptions::default(), &opts)?;
println!(
"commit policy: {:?} | initial state: {:?}",
opts.commit_policy,
stream.state()
);
for (i, frame) in pcm.chunks(1600).enumerate() {
let update = stream.feed(frame)?;
if update.committed_changed || update.tentative_changed {
let text = stream.text();
println!(
"chunk {i:>3} | committed: {:?} | tentative: {:?}",
text.committed, text.tentative
);
}
}
let update = stream.finalize()?;
assert!(update.is_final);
assert_eq!(stream.state(), StreamState::Finished);
let text = stream.text();
println!(
"\nfinal (revision {}): {}",
stream.revision(),
text.full.trim()
);
Ok(())
}