From 82c83c860f47485903a70a5b254731b3d9ad3ea1 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Sun, 9 Oct 2022 20:48:00 -0600 Subject: [PATCH] rename library to whisper-rs --- Cargo.toml | 4 ++-- examples/basic_use.rs | 6 ++--- src/standalone.rs | 6 ++--- src/whisper_ctx.rs | 54 +++++++++++++++++++++---------------------- src/whisper_params.rs | 4 ++-- sys/Cargo.toml | 2 +- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 58c4b0a..9f410d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,14 +2,14 @@ members = ["sys"] [package] -name = "whisper-cpp" +name = "whisper-rs" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -whisper-cpp-sys = { path = "sys", version = "0.1" } +whisper-rs-sys = { path = "sys", version = "0.1" } [features] simd = [] \ No newline at end of file diff --git a/examples/basic_use.rs b/examples/basic_use.rs index de25f03..2ff5ba1 100644 --- a/examples/basic_use.rs +++ b/examples/basic_use.rs @@ -1,4 +1,4 @@ -use whisper_cpp::{DecodeStrategy, FullParams, WhisperContext}; +use whisper_rs::{DecodeStrategy, FullParams, WhisperContext}; // 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 @@ -34,8 +34,8 @@ pub fn usage() { // note that you don't need to use these, you can do it yourself or any other way you want // these are just provided for convenience // SIMD variants of these functions are also available, but only on nightly Rust: see the docs - let audio_data = whisper_cpp::convert_stereo_to_mono_audio( - &whisper_cpp::convert_integer_to_float_audio(&audio_data), + let audio_data = whisper_rs::convert_stereo_to_mono_audio( + &whisper_rs::convert_integer_to_float_audio(&audio_data), ); // now we can run the model diff --git a/src/standalone.rs b/src/standalone.rs index 1f798e2..e111568 100644 --- a/src/standalone.rs +++ b/src/standalone.rs @@ -18,7 +18,7 @@ use std::ffi::{c_int, CString}; /// `int whisper_lang_id(const char * lang)` pub fn get_lang_id(lang: &str) -> Option { let c_lang = CString::new(lang).expect("Language contains null byte"); - let ret = unsafe { whisper_cpp_sys::whisper_lang_id(c_lang.as_ptr()) }; + let ret = unsafe { whisper_rs_sys::whisper_lang_id(c_lang.as_ptr()) }; if ret == -1 { None } else { @@ -32,7 +32,7 @@ pub fn get_lang_id(lang: &str) -> Option { /// # C++ equivalent /// `whisper_token whisper_token_translate ()` pub fn token_translate() -> WhisperToken { - unsafe { whisper_cpp_sys::whisper_token_translate() } + unsafe { whisper_rs_sys::whisper_token_translate() } } /// Get the ID of the transcribe task token. @@ -40,5 +40,5 @@ pub fn token_translate() -> WhisperToken { /// # C++ equivalent /// `whisper_token whisper_token_transcribe()` pub fn token_transcribe() -> WhisperToken { - unsafe { whisper_cpp_sys::whisper_token_transcribe() } + unsafe { whisper_rs_sys::whisper_token_transcribe() } } diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index 318084b..f5e9f33 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -9,7 +9,7 @@ use std::ffi::{c_int, CStr, CString}; /// then run a full transcription with [WhisperContext::full]. #[derive(Debug)] pub struct WhisperContext { - ctx: *mut whisper_cpp_sys::whisper_context, + ctx: *mut whisper_rs_sys::whisper_context, /// has the spectrogram been initialized in at least one way? spectrogram_initialized: bool, /// has the data been encoded? @@ -31,7 +31,7 @@ impl WhisperContext { /// `struct whisper_context * whisper_init(const char * path_model);` pub fn new(path: &str) -> Result { let path_cstr = CString::new(path)?; - let ctx = unsafe { whisper_cpp_sys::whisper_init(path_cstr.as_ptr()) }; + let ctx = unsafe { whisper_rs_sys::whisper_init(path_cstr.as_ptr()) }; if ctx.is_null() { Err(WhisperError::InitError) } else { @@ -61,7 +61,7 @@ impl WhisperContext { return Err(WhisperError::InvalidThreadCount); } let ret = unsafe { - whisper_cpp_sys::whisper_pcm_to_mel( + whisper_rs_sys::whisper_pcm_to_mel( self.ctx, pcm.as_ptr(), pcm.len() as c_int, @@ -94,7 +94,7 @@ impl WhisperContext { /// `int whisper_set_mel(struct whisper_context * ctx, const float * data, int n_len, int n_mel)` pub fn set_mel(&mut self, data: &[f32]) -> Result<(), WhisperError> { let ret = unsafe { - whisper_cpp_sys::whisper_set_mel( + whisper_rs_sys::whisper_set_mel( self.ctx, data.as_ptr(), data.len() as c_int, @@ -129,7 +129,7 @@ impl WhisperContext { return Err(WhisperError::InvalidThreadCount); } let ret = - unsafe { whisper_cpp_sys::whisper_encode(self.ctx, offset as c_int, threads as c_int) }; + unsafe { whisper_rs_sys::whisper_encode(self.ctx, offset as c_int, threads as c_int) }; if ret == 0 { self.encode_complete = true; Ok(()) @@ -166,7 +166,7 @@ impl WhisperContext { return Err(WhisperError::InvalidThreadCount); } let ret = unsafe { - whisper_cpp_sys::whisper_decode( + whisper_rs_sys::whisper_decode( self.ctx, tokens.as_ptr(), tokens.len() as c_int, @@ -198,7 +198,7 @@ impl WhisperContext { if !self.decode_once { return Err(WhisperError::DecodeNotComplete); } - let ret = unsafe { whisper_cpp_sys::whisper_sample_best(self.ctx, needs_timestamp) }; + let ret = unsafe { whisper_rs_sys::whisper_sample_best(self.ctx, needs_timestamp) }; Ok(ret) } @@ -214,7 +214,7 @@ impl WhisperContext { if !self.decode_once { return Err(WhisperError::DecodeNotComplete); } - let ret = unsafe { whisper_cpp_sys::whisper_sample_timestamp(self.ctx) }; + let ret = unsafe { whisper_rs_sys::whisper_sample_timestamp(self.ctx) }; Ok(ret) } @@ -227,7 +227,7 @@ impl WhisperContext { /// # C++ equivalent /// `int whisper_n_len (struct whisper_context * ctx)` pub fn n_len(&self) -> Result { - let ret = unsafe { whisper_cpp_sys::whisper_n_len(self.ctx) }; + let ret = unsafe { whisper_rs_sys::whisper_n_len(self.ctx) }; if ret < 0 { Err(WhisperError::GenericError(ret)) } else { @@ -243,7 +243,7 @@ impl WhisperContext { /// # C++ equivalent /// `int whisper_n_vocab (struct whisper_context * ctx)` pub fn n_vocab(&self) -> Result { - let ret = unsafe { whisper_cpp_sys::whisper_n_vocab(self.ctx) }; + let ret = unsafe { whisper_rs_sys::whisper_n_vocab(self.ctx) }; if ret < 0 { Err(WhisperError::GenericError(ret)) } else { @@ -259,7 +259,7 @@ impl WhisperContext { /// # C++ equivalent /// `int whisper_n_text_ctx (struct whisper_context * ctx)` pub fn n_text_ctx(&self) -> Result { - let ret = unsafe { whisper_cpp_sys::whisper_n_text_ctx(self.ctx) }; + let ret = unsafe { whisper_rs_sys::whisper_n_text_ctx(self.ctx) }; if ret < 0 { Err(WhisperError::GenericError(ret)) } else { @@ -272,7 +272,7 @@ impl WhisperContext { /// # C++ equivalent /// `int whisper_is_multilingual(struct whisper_context * ctx)` pub fn is_multilingual(&self) -> bool { - unsafe { whisper_cpp_sys::whisper_is_multilingual(self.ctx) != 0 } + unsafe { whisper_rs_sys::whisper_is_multilingual(self.ctx) != 0 } } /// The probabilities for the next token. @@ -287,7 +287,7 @@ impl WhisperContext { if !self.decode_once { return Err(WhisperError::DecodeNotComplete); } - let ret = unsafe { whisper_cpp_sys::whisper_get_probs(self.ctx) }; + let ret = unsafe { whisper_rs_sys::whisper_get_probs(self.ctx) }; if ret.is_null() { return Err(WhisperError::NullPointer); } @@ -305,7 +305,7 @@ impl WhisperContext { /// # C++ equivalent /// `const char * whisper_token_to_str(struct whisper_context * ctx, whisper_token token)` pub fn token_to_str(&self, token_id: WhisperToken) -> Result { - let ret = unsafe { whisper_cpp_sys::whisper_token_to_str(self.ctx, token_id) }; + let ret = unsafe { whisper_rs_sys::whisper_token_to_str(self.ctx, token_id) }; if ret.is_null() { return Err(WhisperError::NullPointer); } @@ -320,7 +320,7 @@ impl WhisperContext { /// # C++ equivalent /// `whisper_token whisper_token_eot (struct whisper_context * ctx)` pub fn token_eot(&self) -> WhisperToken { - unsafe { whisper_cpp_sys::whisper_token_eot(self.ctx) } + unsafe { whisper_rs_sys::whisper_token_eot(self.ctx) } } /// Get the ID of the sot token. @@ -328,7 +328,7 @@ impl WhisperContext { /// # C++ equivalent /// `whisper_token whisper_token_sot (struct whisper_context * ctx)` pub fn token_sot(&self) -> WhisperToken { - unsafe { whisper_cpp_sys::whisper_token_sot(self.ctx) } + unsafe { whisper_rs_sys::whisper_token_sot(self.ctx) } } /// Get the ID of the prev token. @@ -336,7 +336,7 @@ impl WhisperContext { /// # C++ equivalent /// `whisper_token whisper_token_prev(struct whisper_context * ctx)` pub fn token_prev(&self) -> WhisperToken { - unsafe { whisper_cpp_sys::whisper_token_prev(self.ctx) } + unsafe { whisper_rs_sys::whisper_token_prev(self.ctx) } } /// Get the ID of the solm token. @@ -344,7 +344,7 @@ impl WhisperContext { /// # C++ equivalent /// `whisper_token whisper_token_solm(struct whisper_context * ctx)` pub fn token_solm(&self) -> WhisperToken { - unsafe { whisper_cpp_sys::whisper_token_solm(self.ctx) } + unsafe { whisper_rs_sys::whisper_token_solm(self.ctx) } } /// Get the ID of the not token. @@ -352,7 +352,7 @@ impl WhisperContext { /// # C++ equivalent /// `whisper_token whisper_token_not (struct whisper_context * ctx)` pub fn token_not(&self) -> WhisperToken { - unsafe { whisper_cpp_sys::whisper_token_not(self.ctx) } + unsafe { whisper_rs_sys::whisper_token_not(self.ctx) } } /// Get the ID of the beg token. @@ -360,7 +360,7 @@ impl WhisperContext { /// # C++ equivalent /// `whisper_token whisper_token_beg (struct whisper_context * ctx)` pub fn token_beg(&self) -> WhisperToken { - unsafe { whisper_cpp_sys::whisper_token_beg(self.ctx) } + unsafe { whisper_rs_sys::whisper_token_beg(self.ctx) } } /// Print performance statistics to stdout. @@ -368,7 +368,7 @@ impl WhisperContext { /// # C++ equivalent /// `void whisper_print_timings(struct whisper_context * ctx)` pub fn print_timings(&self) { - unsafe { whisper_cpp_sys::whisper_print_timings(self.ctx) } + unsafe { whisper_rs_sys::whisper_print_timings(self.ctx) } } /// Run the entire model: PCM -> log mel spectrogram -> encoder -> decoder -> text @@ -387,7 +387,7 @@ impl WhisperContext { /// `int whisper_full(struct whisper_context * ctx, struct whisper_full_params params, const float * samples, int n_samples)` pub fn full(&mut self, params: FullParams, data: &[f32]) -> Result { let ret = unsafe { - whisper_cpp_sys::whisper_full(self.ctx, params.fp, data.as_ptr(), data.len() as c_int) + whisper_rs_sys::whisper_full(self.ctx, params.fp, data.as_ptr(), data.len() as c_int) }; if ret < 0 { Err(WhisperError::GenericError(ret)) @@ -402,7 +402,7 @@ impl WhisperContext { /// # C++ equivalent /// `int whisper_full_n_segments(struct whisper_context * ctx)` pub fn full_n_segments(&self) -> c_int { - unsafe { whisper_cpp_sys::whisper_full_n_segments(self.ctx) } + unsafe { whisper_rs_sys::whisper_full_n_segments(self.ctx) } } /// Get the start time of the specified segment. @@ -413,7 +413,7 @@ impl WhisperContext { /// # C++ equivalent /// `int64_t whisper_full_get_segment_t0(struct whisper_context * ctx, int i_segment)` pub fn full_get_segment_t0(&self, segment: c_int) -> i64 { - unsafe { whisper_cpp_sys::whisper_full_get_segment_t0(self.ctx, segment) } + unsafe { whisper_rs_sys::whisper_full_get_segment_t0(self.ctx, segment) } } /// Get the end time of the specified segment. @@ -424,7 +424,7 @@ impl WhisperContext { /// # C++ equivalent /// `int64_t whisper_full_get_segment_t1(struct whisper_context * ctx, int i_segment)` pub fn full_get_segment_t1(&self, segment: c_int) -> i64 { - unsafe { whisper_cpp_sys::whisper_full_get_segment_t1(self.ctx, segment) } + unsafe { whisper_rs_sys::whisper_full_get_segment_t1(self.ctx, segment) } } /// Get the text of the specified segment. @@ -438,7 +438,7 @@ impl WhisperContext { /// # C++ equivalent /// `const char * whisper_full_get_segment_text(struct whisper_context * ctx, int i_segment)` pub fn full_get_segment_text(&self, segment: c_int) -> Result { - let ret = unsafe { whisper_cpp_sys::whisper_full_get_segment_text(self.ctx, segment) }; + let ret = unsafe { whisper_rs_sys::whisper_full_get_segment_text(self.ctx, segment) }; if ret.is_null() { return Err(WhisperError::NullPointer); } @@ -450,6 +450,6 @@ impl WhisperContext { impl Drop for WhisperContext { fn drop(&mut self) { - unsafe { whisper_cpp_sys::whisper_free(self.ctx) }; + unsafe { whisper_rs_sys::whisper_free(self.ctx) }; } } diff --git a/src/whisper_params.rs b/src/whisper_params.rs index 782a6af..fb06b4d 100644 --- a/src/whisper_params.rs +++ b/src/whisper_params.rs @@ -14,7 +14,7 @@ pub enum DecodeStrategy { } pub struct FullParams<'a> { - pub(crate) fp: whisper_cpp_sys::whisper_full_params, + pub(crate) fp: whisper_rs_sys::whisper_full_params, phantom: PhantomData<&'a str>, } @@ -22,7 +22,7 @@ impl<'a> FullParams<'a> { /// Create a new set of parameters for the decoder. pub fn new(decode_strategy: DecodeStrategy) -> FullParams<'a> { let mut fp = unsafe { - whisper_cpp_sys::whisper_full_default_params(match decode_strategy { + whisper_rs_sys::whisper_full_default_params(match decode_strategy { DecodeStrategy::Greedy { .. } => 0, DecodeStrategy::BeamSearch { .. } => 1, } as _) diff --git a/sys/Cargo.toml b/sys/Cargo.toml index 57db3d4..dff8f40 100644 --- a/sys/Cargo.toml +++ b/sys/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "whisper-cpp-sys" +name = "whisper-rs-sys" version = "0.1.0" edition = "2021"