Skip to content

Add UniFFI interface for livekit-wakeword#939

Open
pham-tuan-binh wants to merge 7 commits intomainfrom
binhpham/uniffi-wakeword
Open

Add UniFFI interface for livekit-wakeword#939
pham-tuan-binh wants to merge 7 commits intomainfrom
binhpham/uniffi-wakeword

Conversation

@pham-tuan-binh
Copy link
Contributor

Summary

  • Expose WakeWordDetector as a UniFFI Object wrapping WakeWordModel with Mutex for interior mutability
  • Export new, load_model, and predict methods across FFI
  • Use #[uniffi::remote(Error)] with #[uniffi(flat_error)] for WakeWordError, matching the existing AccessTokenError pattern

Test plan

  • cargo check -p livekit-uniffi passes
  • Add wakeword test cases to Node/Python integration tests

Expose WakeWordDetector as a UniFFI Object wrapping WakeWordModel
with Mutex for interior mutability. Includes a flat wrapper error
type that converts from WakeWordError since its inner types
(ort::Error, ndarray::ShapeError, etc.) are not UniFFI-compatible.
Drop the thiserror wrapper error and From impl in favor of
#[uniffi::remote(Error)] with #[uniffi(flat_error)], matching the
pattern used by AccessTokenError. Removes the thiserror dependency
from livekit-uniffi.
@pham-tuan-binh pham-tuan-binh requested a review from ladvoc March 12, 2026 06:45
Fixes Windows CI linking error by enabling ort to download prebuilt
ONNX Runtime binaries on all platforms.
The prebuilt ONNX Runtime binaries from ort's download-binaries feature
are built with dynamic CRT (/MD), which conflicts with +crt-static (/MT)
causing unresolved symbols for CRT functions.
///
/// Pass ~2 seconds of i16 PCM audio at the sample rate configured in
/// [`new`](Self::new). Returns a map of classifier name to confidence score.
pub fn predict(&self, audio_chunk: Vec<i16>) -> Result<HashMap<String, f32>, WakeWordError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This can accept a non-mutable slice &[i16] to avoid cloning. This is also supported by UniFFI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I didn't know that, will make a commit

[dependencies]
ndarray = "0.17.2"
ort = { version = "2.0.0-rc.11", default-features = false, features = ["ndarray", "std"] }
ort = { version = "2.0.0-rc.11", default-features = false, features = ["ndarray", "std", "download-binaries", "tls-native"] }
Copy link
Contributor

@ladvoc ladvoc Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Which binaries does ORT need to download? If this is necessary, we shouldn't hardcode tls-native and instead allow the consumer of the crate to choose the TLS feature they want to use based on their requirements (much like how ort does so itself).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't necessary. It was a suggestion from copilot to solve linking problems on Windows. Would u mind looking into the problem on windows for me @ladvoc ? It has some weird problems with the way our rust config is handled on windows.

Copy link
Contributor

@ladvoc ladvoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Some initial comments

@ladvoc
Copy link
Contributor

ladvoc commented Mar 12, 2026

I placed wake word support in livekit-uniffi behind a feature so we have the option to build without it.

@ladvoc
Copy link
Contributor

ladvoc commented Mar 12, 2026

@pblazej, if we were to integrate this into the Swift SDK, what questions/concerns would you have (e.g., dylib size)? As I noted above, wakework support is behind a feature so we can compile without support for it for now.

@pblazej
Copy link
Contributor

pblazej commented Mar 13, 2026

Surprisingly, we currently use a static lib as you cannot ship a bare dylib to App Store (without wrapping in another Framework).

We may revisit that in the future, no complaints yet about the bundle size per se.

@pham-tuan-binh
Copy link
Contributor Author

I placed wake word support in livekit-uniffi behind a feature so we have the option to build without it.

would it be fine to just disable building with wakeword on windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants