How picovoice/rhino works
Project Type and Purpose
• This is an open-source, cross-platform Speech-to-Intent SDK (“Rhino”) with:
• A native, ANSI C core engine (pv_rhino) and parameter model (rhino_params.pv).
• Multi-language FFI bindings (Python, Node.js, Java, .NET, Rust, Android/Java, iOS/Swift, Flutter, React Native, Unity, Web/WASM).
• Reference demo applications per platform.
• Build and CI pipelines validating builds, style, demos, and performance.
File Structure
• Top level
• include/ and lib/: header and compiled native libraries for each platform/architecture.
• binding/<platform>/: language-specific wrapper code and packaging (e.g., binding/python, binding/nodejs, binding/android/Rhino).
• demo/<platform>/: reference apps showing how to use the SDK on each platform (e.g., demo/python, demo/web, demo/android/Activity).
• resources/contexts/ and lib/common/rhino_params.pv: shipped context files (.rhn) and model (.pv).
• .github/workflows/: CI jobs for style, build, demo, performance on each supported language.
• script/ and resources/scripts/: automation and lint/test helpers.
README Insights
• Core engine infers “intent” and “slots” from microphone or audio file input.
• Broad language/platform support, including WebAssembly in a Web Worker.
• Demos illustrate both file-based and microphone-based usage.
• SDK sections detail high-level (automatic audio capture) vs. low-level APIs.
Main Components
a. Rhino Core Engine
• C library & model: pv_rhino.h + rhino_params.pv (lib/common).
• Exposed via FFI or WebAssembly.
b. Context Model Store
• Static .rhn files under resources/contexts/<platform> loaded at runtime.
c. Language Bindings (Adapters)
• Python (binding/python)
• Node.js (binding/nodejs)
• Java (binding/java)
• .NET (binding/dotnet)
• Rust (binding/rust)
• Android (Java JNI) (binding/android/Rhino)
• iOS (Swift/Obj-C) (binding/ios)
• Flutter (binding/flutter)
• React Native (binding/react-native)
• Unity (binding/unity)
• Web/WASM (binding/web) via Web Worker + WebVoiceProcessor
d. Demo Applications
• One per platform under demo/<platform> – using corresponding binding + context + audio I/O.
e. CI / Build Pipeline
• GitHub Actions jobs for each binding: style check, build, demo smoke tests, perf benchmarks.
f. Utilities & Scripts
• Linting, test data, automation scripts under resources/.lint, resources/.test, resources/scripts, script/automation.
Relationships and Data Flows
• Audio Input (Mic or File) → Binding (high-level or low-level API) → Rhino Core Engine (FFI/WASM) + Context → Inference Result → Binding → Demo/Application UI or CLI.
• CI pipelines pull from repo → build native libs (lib/), compile bindings, run demos/tests.
Architectural Patterns and Design Principles
• Adapter/Bridge pattern: each language binding adapts the uniform C API to a language-specific idiom.
• Plugin-like model loading: contexts (.rhn) and model (.pv) are data plugins.
• Polyglot monorepo: shared core, multiple language surfaces.
• Isolation for web: WebAssembly + Web Worker for non-blocking inference.
• High-Level vs. Low-Level API: automatic audio capture vs. manual frame feeding.