Merge pull request #163 from arizhih/fix-lang-detect
fix: lang_detect not working properly
This commit is contained in:
commit
744804a8aa
4 changed files with 14 additions and 23 deletions
|
|
@ -4,7 +4,7 @@ exclude = ["examples/full_usage"]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "whisper-rs"
|
name = "whisper-rs"
|
||||||
version = "0.12.0"
|
version = "0.12.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Rust bindings for whisper.cpp"
|
description = "Rust bindings for whisper.cpp"
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
|
|
@ -14,7 +14,7 @@ repository = "https://github.com/tazz4843/whisper-rs"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
whisper-rs-sys = { path = "sys", version = "0.10.0" }
|
whisper-rs-sys = { path = "sys", version = "0.10.1" }
|
||||||
log = { version = "0.4", optional = true }
|
log = { version = "0.4", optional = true }
|
||||||
tracing = { version = "0.1", optional = true }
|
tracing = { version = "0.1", optional = true }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -225,11 +225,16 @@ impl WhisperState {
|
||||||
/// * n_threads: How many threads to use. Defaults to 1. Must be at least 1, returns an error otherwise.
|
/// * n_threads: How many threads to use. Defaults to 1. Must be at least 1, returns an error otherwise.
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
/// `Ok(Vec<f32>)` on success, `Err(WhisperError)` on failure.
|
/// `Ok((i32, Vec<f32>))` on success where the i32 is detected language id and Vec<f32>
|
||||||
|
/// is array with the probabilities of all languages, `Err(WhisperError)` on failure.
|
||||||
///
|
///
|
||||||
/// # C++ equivalent
|
/// # C++ equivalent
|
||||||
/// `int whisper_lang_auto_detect(struct whisper_context * ctx, int offset_ms, int n_threads, float * lang_probs)`
|
/// `int whisper_lang_auto_detect(struct whisper_context * ctx, int offset_ms, int n_threads, float * lang_probs)`
|
||||||
pub fn lang_detect(&self, offset_ms: usize, threads: usize) -> Result<Vec<f32>, WhisperError> {
|
pub fn lang_detect(
|
||||||
|
&self,
|
||||||
|
offset_ms: usize,
|
||||||
|
threads: usize,
|
||||||
|
) -> Result<(i32, Vec<f32>), WhisperError> {
|
||||||
if threads < 1 {
|
if threads < 1 {
|
||||||
return Err(WhisperError::InvalidThreadCount);
|
return Err(WhisperError::InvalidThreadCount);
|
||||||
}
|
}
|
||||||
|
|
@ -244,25 +249,10 @@ impl WhisperState {
|
||||||
lang_probs.as_mut_ptr(),
|
lang_probs.as_mut_ptr(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
if ret == -1 {
|
if ret < 0 {
|
||||||
Err(WhisperError::UnableToCalculateEvaluation)
|
Err(WhisperError::GenericError(ret))
|
||||||
} else {
|
} else {
|
||||||
assert_eq!(
|
Ok((ret as i32, lang_probs))
|
||||||
ret as usize,
|
|
||||||
lang_probs.len(),
|
|
||||||
"lang_probs length mismatch: this is a bug in whisper.cpp"
|
|
||||||
);
|
|
||||||
// if we're still running, double check that the length is correct, otherwise print to stderr
|
|
||||||
// and abort, as this will cause Undefined Behavior
|
|
||||||
// might get here due to the unwind being caught by a user-installed panic handler
|
|
||||||
if lang_probs.len() != ret as usize {
|
|
||||||
eprintln!(
|
|
||||||
"lang_probs length mismatch: this is a bug in whisper.cpp, \
|
|
||||||
aborting to avoid Undefined Behavior"
|
|
||||||
);
|
|
||||||
std::process::abort();
|
|
||||||
}
|
|
||||||
Ok(lang_probs)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "whisper-rs-sys"
|
name = "whisper-rs-sys"
|
||||||
version = "0.10.0"
|
version = "0.10.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Rust bindings for whisper.cpp (FFI bindings)"
|
description = "Rust bindings for whisper.cpp (FFI bindings)"
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,7 @@ fn main() {
|
||||||
// debug builds are too slow to even remotely be usable,
|
// debug builds are too slow to even remotely be usable,
|
||||||
// so we build with optimizations even in debug mode
|
// so we build with optimizations even in debug mode
|
||||||
config.define("CMAKE_BUILD_TYPE", "RelWithDebInfo");
|
config.define("CMAKE_BUILD_TYPE", "RelWithDebInfo");
|
||||||
|
config.cxxflag("-DWHISPER_DEBUG");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow passing any WHISPER or CMAKE compile flags
|
// Allow passing any WHISPER or CMAKE compile flags
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue