Initial commit

This commit is contained in:
0/0 2022-10-09 20:17:31 -06:00
commit e12122a6ed
No known key found for this signature in database
GPG key ID: DE8D5010C0AAA3DC
15 changed files with 927 additions and 0 deletions

44
src/standalone.rs Normal file
View file

@ -0,0 +1,44 @@
//! Standalone functions that have no associated type.
use crate::WhisperToken;
use std::ffi::{c_int, CString};
/// Return the id of the specified language, returns -1 if not found
///
/// # Arguments
/// * lang: The language to get the id for.
///
/// # Returns
/// The ID of the language, None if not found.
///
/// # Panics
/// Panics if the language contains a null byte.
///
/// # C++ equivalent
/// `int whisper_lang_id(const char * lang)`
pub fn get_lang_id(lang: &str) -> Option<c_int> {
let c_lang = CString::new(lang).expect("Language contains null byte");
let ret = unsafe { whisper_cpp_sys::whisper_lang_id(c_lang.as_ptr()) };
if ret == -1 {
None
} else {
Some(ret)
}
}
// task tokens
/// Get the ID of the translate task token.
///
/// # C++ equivalent
/// `whisper_token whisper_token_translate ()`
pub fn token_translate() -> WhisperToken {
unsafe { whisper_cpp_sys::whisper_token_translate() }
}
/// Get the ID of the transcribe task token.
///
/// # C++ equivalent
/// `whisper_token whisper_token_transcribe()`
pub fn token_transcribe() -> WhisperToken {
unsafe { whisper_cpp_sys::whisper_token_transcribe() }
}