Skip to main content

nemotron_asr_sys/
lib.rs

1//! Low-level FFI bindings for nemotron-asr.cpp
2//!
3//! This crate provides raw, unsafe bindings to the C API of nemotron-asr.cpp.
4//! For a safe, idiomatic Rust API, use the `nemotron-asr` crate instead.
5//!
6//! # Usage
7//!
8//! The bindings are automatically generated from the C header files using bindgen.
9//! All functions are unsafe and require careful handling of pointers and memory management.
10//!
11//! # Example
12//!
13//! ```no_run
14//! use nemotron_asr_sys::*;
15//! use std::ffi::CString;
16//! use std::ptr;
17//!
18//! unsafe {
19//!     // Initialize model with default backend
20//!     let model_path = CString::new("/path/to/model.gguf").unwrap();
21//!     let ctx = c_nemo_init_with_backend(model_path.as_ptr(), ptr::null());
22//!
23//!     if !ctx.is_null() {
24//!         // Create streaming context with default config
25//!         let stream_ctx = c_nemo_stream_init(ctx, ptr::null());
26//!
27//!         // Process audio...
28//!
29//!         // Cleanup
30//!         c_nemo_stream_free(stream_ctx);
31//!         c_nemo_free(ctx);
32//!     }
33//! }
34//! ```
35
36#![allow(non_upper_case_globals)]
37#![allow(non_camel_case_types)]
38#![allow(non_snake_case)]
39
40// Include the bindings (either pre-generated or generated with bindgen feature)
41include!("bindings.rs");
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_cache_config_default() {
49        unsafe {
50            let config = nemo_cache_config_default();
51            assert_eq!(config.sample_rate, 16000);
52            assert_eq!(config.n_mels, 128);
53        }
54    }
55
56    #[test]
57    fn test_latency_mode_values() {
58        assert_eq!(nemo_latency_mode::NEMO_LATENCY_PURE_CAUSAL as i32, 0);
59        assert_eq!(nemo_latency_mode::NEMO_LATENCY_ULTRA_LOW as i32, 1);
60        assert_eq!(nemo_latency_mode::NEMO_LATENCY_LOW as i32, 6);
61        assert_eq!(nemo_latency_mode::NEMO_LATENCY_DEFAULT as i32, 13);
62    }
63}