use std::ffi::c_int;
use std::marker::PhantomData;
pub enum DecodeStrategy {
Greedy {
n_past: c_int,
},
BeamSearch {
n_past: c_int,
beam_width: c_int,
n_best: c_int,
},
}
pub struct FullParams<'a> {
pub(crate) fp: whisper_rs_sys::whisper_full_params,
phantom: PhantomData<&'a str>,
}
impl<'a> FullParams<'a> {
pub fn new(decode_strategy: DecodeStrategy) -> FullParams<'a> {
let mut fp = unsafe {
whisper_rs_sys::whisper_full_default_params(match decode_strategy {
DecodeStrategy::Greedy { .. } => 0,
DecodeStrategy::BeamSearch { .. } => 1,
} as _)
};
match decode_strategy {
DecodeStrategy::Greedy { n_past } => {
fp.__bindgen_anon_1.greedy.n_past = n_past;
}
DecodeStrategy::BeamSearch {
n_past,
beam_width,
n_best,
} => {
fp.__bindgen_anon_1.beam_search.n_past = n_past;
fp.__bindgen_anon_1.beam_search.beam_width = beam_width;
fp.__bindgen_anon_1.beam_search.n_best = n_best;
}
}
Self {
fp,
phantom: PhantomData,
}
}
pub fn set_n_threads(&mut self, n_threads: c_int) {
self.fp.n_threads = n_threads;
}
pub fn set_offset_ms(&mut self, offset_ms: c_int) {
self.fp.offset_ms = offset_ms;
}
pub fn set_translate(&mut self, translate: bool) {
self.fp.translate = translate;
}
pub fn set_no_context(&mut self, no_context: bool) {
self.fp.no_context = no_context;
}
pub fn set_print_special_tokens(&mut self, print_special_tokens: bool) {
self.fp.print_special_tokens = print_special_tokens;
}
pub fn set_print_progress(&mut self, print_progress: bool) {
self.fp.print_progress = print_progress;
}
pub fn set_print_realtime(&mut self, print_realtime: bool) {
self.fp.print_realtime = print_realtime;
}
pub fn set_print_timestamps(&mut self, print_timestamps: bool) {
self.fp.print_timestamps = print_timestamps;
}
pub fn set_language(&mut self, language: &'a str) {
self.fp.language = language.as_ptr() as *const _;
}
}
unsafe impl<'a> Send for FullParams<'a> {}
unsafe impl<'a> Sync for FullParams<'a> {}