aic_sdk/
lib.rs

1#![doc = include_str!("../README.md")]
2use aic_sdk_sys::{aic_get_compatible_model_version, aic_get_sdk_version, aic_set_sdk_wrapper_id};
3use std::ffi::CStr;
4
5#[cfg(feature = "download-model")]
6mod download;
7mod error;
8mod model;
9mod processor;
10mod vad;
11
12pub use error::*;
13pub use model::*;
14pub use processor::*;
15pub use vad::*;
16
17/// Returns the version of the ai-coustics SDK library.
18///
19/// # Note
20/// This is not necessarily the same as this crate's version.
21///
22/// # Returns
23///
24/// Returns the SDK version string, or `"unknown"` if it cannot be decoded.
25///
26/// # Example
27///
28/// ```rust
29/// let version = aic_sdk::get_sdk_version();
30/// println!("ai-coustics SDK version: {version}");
31/// ```
32pub fn get_sdk_version() -> &'static str {
33    // SAFETY:
34    // - FFI call returns a pointer to a static C string owned by the SDK.
35    // - The pointer can never be null, so no check is necessary.
36    let version_ptr = unsafe { aic_get_sdk_version() };
37
38    // SAFETY:
39    // - SDK returns a null-terminated static string.
40    unsafe { CStr::from_ptr(version_ptr).to_str().unwrap_or("unknown") }
41}
42
43/// Returns the model version number compatible with this SDK build.
44pub fn get_compatible_model_version() -> u32 {
45    // SAFETY:
46    // - FFI call takes no arguments and returns a plain integer.
47    unsafe { aic_get_compatible_model_version() }
48}
49
50/// This function is only used to identify SDKs by ai-coustics and should not be called by users of this crate.
51///
52/// # Safety
53///
54/// - Don't call this function unless you know what you're doing.
55pub unsafe fn set_sdk_id(id: u32) {
56    // SAFETY:
57    // - This FFI call has no safety requirements.
58    unsafe { aic_set_sdk_wrapper_id(id) }
59}