From 6df5ed5ab6c738e194bbaad9ccad893f44279178 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Mon, 10 Oct 2022 11:04:34 -0600 Subject: [PATCH] add fallback bindings if whisper.h can't be found --- sys/src/bindings.rs | 545 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 545 insertions(+) create mode 100644 sys/src/bindings.rs diff --git a/sys/src/bindings.rs b/sys/src/bindings.rs new file mode 100644 index 0000000..449b3aa --- /dev/null +++ b/sys/src/bindings.rs @@ -0,0 +1,545 @@ +/* automatically generated by rust-bindgen 0.60.1 */ + +pub const true_: u32 = 1; +pub const false_: u32 = 0; +pub const __bool_true_false_are_defined: u32 = 1; +pub const WHISPER_SAMPLE_RATE: u32 = 16000; +pub const WHISPER_N_FFT: u32 = 400; +pub const WHISPER_N_MEL: u32 = 80; +pub const WHISPER_HOP_LENGTH: u32 = 160; +pub const WHISPER_CHUNK_SIZE: u32 = 30; +pub type int_least64_t = i64; +pub type uint_least64_t = u64; +pub type int_fast64_t = i64; +pub type uint_fast64_t = u64; +pub type int_least32_t = i32; +pub type uint_least32_t = u32; +pub type int_fast32_t = i32; +pub type uint_fast32_t = u32; +pub type int_least16_t = i16; +pub type uint_least16_t = u16; +pub type int_fast16_t = i16; +pub type uint_fast16_t = u16; +pub type int_least8_t = i8; +pub type uint_least8_t = u8; +pub type int_fast8_t = i8; +pub type uint_fast8_t = u8; +pub type intmax_t = ::std::os::raw::c_long; +pub type uintmax_t = ::std::os::raw::c_ulong; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct whisper_context { + _unused: [u8; 0], +} +pub type whisper_token = ::std::os::raw::c_int; +extern "C" { + pub fn whisper_init(path_model: *const ::std::os::raw::c_char) -> *mut whisper_context; +} +extern "C" { + pub fn whisper_free(ctx: *mut whisper_context); +} +extern "C" { + pub fn whisper_pcm_to_mel( + ctx: *mut whisper_context, + samples: *const f32, + n_samples: ::std::os::raw::c_int, + n_threads: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_set_mel( + ctx: *mut whisper_context, + data: *const f32, + n_len: ::std::os::raw::c_int, + n_mel: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_encode( + ctx: *mut whisper_context, + offset: ::std::os::raw::c_int, + n_threads: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_decode( + ctx: *mut whisper_context, + tokens: *const whisper_token, + n_tokens: ::std::os::raw::c_int, + n_past: ::std::os::raw::c_int, + n_threads: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_sample_best(ctx: *mut whisper_context, need_timestamp: bool) -> whisper_token; +} +extern "C" { + pub fn whisper_sample_timestamp(ctx: *mut whisper_context) -> whisper_token; +} +extern "C" { + pub fn whisper_lang_id(lang: *const ::std::os::raw::c_char) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_n_len(ctx: *mut whisper_context) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_n_vocab(ctx: *mut whisper_context) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_n_text_ctx(ctx: *mut whisper_context) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_is_multilingual(ctx: *mut whisper_context) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_get_probs(ctx: *mut whisper_context) -> *mut f32; +} +extern "C" { + pub fn whisper_token_to_str( + ctx: *mut whisper_context, + token: whisper_token, + ) -> *const ::std::os::raw::c_char; +} +extern "C" { + pub fn whisper_token_eot(ctx: *mut whisper_context) -> whisper_token; +} +extern "C" { + pub fn whisper_token_sot(ctx: *mut whisper_context) -> whisper_token; +} +extern "C" { + pub fn whisper_token_prev(ctx: *mut whisper_context) -> whisper_token; +} +extern "C" { + pub fn whisper_token_solm(ctx: *mut whisper_context) -> whisper_token; +} +extern "C" { + pub fn whisper_token_not(ctx: *mut whisper_context) -> whisper_token; +} +extern "C" { + pub fn whisper_token_beg(ctx: *mut whisper_context) -> whisper_token; +} +extern "C" { + pub fn whisper_token_translate() -> whisper_token; +} +extern "C" { + pub fn whisper_token_transcribe() -> whisper_token; +} +extern "C" { + pub fn whisper_print_timings(ctx: *mut whisper_context); +} +pub const whisper_decode_strategy_WHISPER_DECODE_GREEDY: whisper_decode_strategy = 0; +pub const whisper_decode_strategy_WHISPER_DECODE_BEAM_SEARCH: whisper_decode_strategy = 1; +#[doc = ""] +pub type whisper_decode_strategy = ::std::os::raw::c_uint; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct whisper_full_params { + pub strategy: whisper_decode_strategy, + pub n_threads: ::std::os::raw::c_int, + pub offset_ms: ::std::os::raw::c_int, + pub translate: bool, + pub no_context: bool, + pub print_special_tokens: bool, + pub print_progress: bool, + pub print_realtime: bool, + pub print_timestamps: bool, + pub language: *const ::std::os::raw::c_char, + pub __bindgen_anon_1: whisper_full_params__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union whisper_full_params__bindgen_ty_1 { + pub greedy: whisper_full_params__bindgen_ty_1__bindgen_ty_1, + pub beam_search: whisper_full_params__bindgen_ty_1__bindgen_ty_2, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct whisper_full_params__bindgen_ty_1__bindgen_ty_1 { + pub n_past: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_whisper_full_params__bindgen_ty_1__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 4usize, + concat!( + "Size of: ", + stringify!(whisper_full_params__bindgen_ty_1__bindgen_ty_1) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(whisper_full_params__bindgen_ty_1__bindgen_ty_1) + ) + ); + fn test_field_n_past() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + whisper_full_params__bindgen_ty_1__bindgen_ty_1, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).n_past) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params__bindgen_ty_1__bindgen_ty_1), + "::", + stringify!(n_past) + ) + ); + } + test_field_n_past(); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct whisper_full_params__bindgen_ty_1__bindgen_ty_2 { + pub n_past: ::std::os::raw::c_int, + pub beam_width: ::std::os::raw::c_int, + pub n_best: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_whisper_full_params__bindgen_ty_1__bindgen_ty_2() { + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!( + "Size of: ", + stringify!(whisper_full_params__bindgen_ty_1__bindgen_ty_2) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(whisper_full_params__bindgen_ty_1__bindgen_ty_2) + ) + ); + fn test_field_n_past() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + whisper_full_params__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).n_past) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(n_past) + ) + ); + } + test_field_n_past(); + fn test_field_beam_width() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + whisper_full_params__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).beam_width) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(beam_width) + ) + ); + } + test_field_beam_width(); + fn test_field_n_best() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::< + whisper_full_params__bindgen_ty_1__bindgen_ty_2, + >::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).n_best) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params__bindgen_ty_1__bindgen_ty_2), + "::", + stringify!(n_best) + ) + ); + } + test_field_n_best(); +} +#[test] +fn bindgen_test_layout_whisper_full_params__bindgen_ty_1() { + assert_eq!( + ::std::mem::size_of::(), + 12usize, + concat!("Size of: ", stringify!(whisper_full_params__bindgen_ty_1)) + ); + assert_eq!( + ::std::mem::align_of::(), + 4usize, + concat!( + "Alignment of ", + stringify!(whisper_full_params__bindgen_ty_1) + ) + ); + fn test_field_greedy() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).greedy) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params__bindgen_ty_1), + "::", + stringify!(greedy) + ) + ); + } + test_field_greedy(); + fn test_field_beam_search() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).beam_search) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params__bindgen_ty_1), + "::", + stringify!(beam_search) + ) + ); + } + test_field_beam_search(); +} +#[test] +fn bindgen_test_layout_whisper_full_params() { + assert_eq!( + ::std::mem::size_of::(), + 48usize, + concat!("Size of: ", stringify!(whisper_full_params)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(whisper_full_params)) + ); + fn test_field_strategy() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).strategy) as usize - ptr as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(strategy) + ) + ); + } + test_field_strategy(); + fn test_field_n_threads() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).n_threads) as usize - ptr as usize + }, + 4usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(n_threads) + ) + ); + } + test_field_n_threads(); + fn test_field_offset_ms() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).offset_ms) as usize - ptr as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(offset_ms) + ) + ); + } + test_field_offset_ms(); + fn test_field_translate() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).translate) as usize - ptr as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(translate) + ) + ); + } + test_field_translate(); + fn test_field_no_context() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).no_context) as usize - ptr as usize + }, + 13usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(no_context) + ) + ); + } + test_field_no_context(); + fn test_field_print_special_tokens() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).print_special_tokens) as usize - ptr as usize + }, + 14usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(print_special_tokens) + ) + ); + } + test_field_print_special_tokens(); + fn test_field_print_progress() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).print_progress) as usize - ptr as usize + }, + 15usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(print_progress) + ) + ); + } + test_field_print_progress(); + fn test_field_print_realtime() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).print_realtime) as usize - ptr as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(print_realtime) + ) + ); + } + test_field_print_realtime(); + fn test_field_print_timestamps() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).print_timestamps) as usize - ptr as usize + }, + 17usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(print_timestamps) + ) + ); + } + test_field_print_timestamps(); + fn test_field_language() { + assert_eq!( + unsafe { + let uninit = ::std::mem::MaybeUninit::::uninit(); + let ptr = uninit.as_ptr(); + ::std::ptr::addr_of!((*ptr).language) as usize - ptr as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(whisper_full_params), + "::", + stringify!(language) + ) + ); + } + test_field_language(); +} +extern "C" { + pub fn whisper_full_default_params(strategy: whisper_decode_strategy) -> whisper_full_params; +} +extern "C" { + pub fn whisper_full( + ctx: *mut whisper_context, + params: whisper_full_params, + samples: *const f32, + n_samples: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_full_n_segments(ctx: *mut whisper_context) -> ::std::os::raw::c_int; +} +extern "C" { + pub fn whisper_full_get_segment_t0( + ctx: *mut whisper_context, + i_segment: ::std::os::raw::c_int, + ) -> i64; +} +extern "C" { + pub fn whisper_full_get_segment_t1( + ctx: *mut whisper_context, + i_segment: ::std::os::raw::c_int, + ) -> i64; +} +extern "C" { + pub fn whisper_full_get_segment_text( + ctx: *mut whisper_context, + i_segment: ::std::os::raw::c_int, + ) -> *const ::std::os::raw::c_char; +}