From 212c7e9de296a7a3b5fb2086d5357c1f0b4eaa5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81lvarez?= Date: Tue, 29 Aug 2023 16:40:33 +0200 Subject: [PATCH] use beta-5 --- binding/Cargo.lock | 22 ++++---- binding/Cargo.toml | 4 +- binding/src/java_glue.rs.in | 53 +++++++++++++------ pom.xml | 2 +- .../givimad/rustpotter_java/Rustpotter.java | 16 +++--- .../rustpotter_java/RustpotterBuilder.java | 13 +++++ .../givimad/rustpotter_java/VADMode.java | 25 +++++++++ 7 files changed, 96 insertions(+), 39 deletions(-) create mode 100644 src/main/java/io/github/givimad/rustpotter_java/VADMode.java diff --git a/binding/Cargo.lock b/binding/Cargo.lock index 0b90443..8333af4 100644 --- a/binding/Cargo.lock +++ b/binding/Cargo.lock @@ -63,9 +63,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "candle-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e56d08f7794036648d7ba5448c82ab7c3f38c25e90cdc4032afd246d1292a42c" +checksum = "1a14e585d4632a3c278c03d69db4e3595801cceeb72f329da099bb687025b05c" dependencies = [ "byteorder", "candle-gemm", @@ -208,9 +208,9 @@ dependencies = [ [[package]] name = "candle-nn" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fba63698e86c8d82c9851181d7f2fa8cede3956a0c9172d74e5ea6ee36ff6b6a" +checksum = "fdf20b6d0b76ee97b9438763972b17e0f1204bffb31c9f1fd4f7a30446a4b4b1" dependencies = [ "candle-core", "safetensors", @@ -766,9 +766,9 @@ dependencies = [ [[package]] name = "rustpotter" -version = "3.0.0-beta.4" +version = "3.0.0-beta.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62e73cbed04283cc5af1dd62c019c9bc25c2637eb63a9cbca8839e2a3c740489" +checksum = "f222bac1ebe5c020312fce48ee2d8c489e5247327d4246356e5a07738705c488" dependencies = [ "candle-core", "candle-nn", @@ -781,7 +781,7 @@ dependencies = [ [[package]] name = "rustpotter-java" -version = "3.0.0-beta.4" +version = "3.0.0-beta.5" dependencies = [ "bindgen", "flapigen", @@ -825,18 +825,18 @@ checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4" [[package]] name = "serde" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", diff --git a/binding/Cargo.toml b/binding/Cargo.toml index 1a89f5b..6ddf59c 100644 --- a/binding/Cargo.toml +++ b/binding/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustpotter-java" -version = "3.0.0-beta.4" +version = "3.0.0-beta.5" edition = "2021" description = "Java binding for Rustpotter, an open source wakeword spotter forged in rust." @@ -10,7 +10,7 @@ crate-type = ["cdylib"] [dependencies] log = "^0.4.19" -rustpotter = { version = "3.0.0-beta.4", features = [ "debug", "record" ] } +rustpotter = { version = "3.0.0-beta.5", features = [ "debug", "record" ] } [build-dependencies] flapigen = "0.6.0" diff --git a/binding/src/java_glue.rs.in b/binding/src/java_glue.rs.in index 15e9c34..72de432 100644 --- a/binding/src/java_glue.rs.in +++ b/binding/src/java_glue.rs.in @@ -2,7 +2,7 @@ use crate::jni_c_header::*; use rustpotter::{ Endianness, Rustpotter as RustpotterImpl, RustpotterConfig, - RustpotterDetection as RustpotterDetectionImpl, SampleFormat, ScoreMode, + RustpotterDetection as RustpotterDetectionImpl, SampleFormat, ScoreMode, VADMode, }; pub struct RustpotterDetection { detection: RustpotterDetectionImpl, @@ -73,6 +73,9 @@ impl RustpotterBuilder { pub fn setScoreMode(&mut self, value: ScoreMode) { self.config.detector.score_mode = value.into(); } + pub fn setVADMode(&mut self, value: Option) { + self.config.detector.vad_mode = value.into(); + } pub fn setSampleRate(&mut self, value: usize) { self.config.fmt.sample_rate = value; } @@ -127,28 +130,32 @@ pub struct Rustpotter { } #[allow(non_snake_case)] impl Rustpotter { - pub fn addWakewordModelFile(&mut self, path: String) -> Result<(), String> { + pub fn addWakewordFile(&mut self, path: String) -> Result<(), String> { self.rustpotter.add_wakeword_from_file(&path) } - pub fn addWakewordModelBytes(&mut self, bytes: &[u8]) -> Result<(), String> { + pub fn addWakewordBytes(&mut self, bytes: &[u8]) -> Result<(), String> { self.rustpotter.add_wakeword_from_buffer(&bytes) } pub fn removeWakeword(&mut self, name: &str) { self.rustpotter.remove_wakeword(name); } pub fn processBytes(&mut self, bytes: &[u8]) -> Option { - self.rustpotter - .process_bytes(bytes) - .map(|d| d.into()) + self.rustpotter.process_bytes(bytes).map(|d| d.into()) } pub fn processSort(&mut self, samples: &[i16]) -> Option { - self.rustpotter.process_samples(samples.into()).map(|d| d.into()) + self.rustpotter + .process_samples(samples.into()) + .map(|d| d.into()) } pub fn processInt(&mut self, samples: &[i32]) -> Option { - self.rustpotter.process_samples(samples.into()).map(|d| d.into()) + self.rustpotter + .process_samples(samples.into()) + .map(|d| d.into()) } pub fn processFloat(&mut self, samples: &[f32]) -> Option { - self.rustpotter.process_samples(samples.into()).map(|d| d.into()) + self.rustpotter + .process_samples(samples.into()) + .map(|d| d.into()) } pub fn getSamplesPerFrame(&self) -> usize { self.rustpotter.get_samples_per_frame() @@ -191,6 +198,14 @@ foreign_enum!( NATIVE = Endianness::Native, } ); +foreign_enum!( + /// Supported vad modes. + enum VADMode { + EASY = VADMode::Easy, + MEDIUM = VADMode::Medium, + HARD = VADMode::Hard, + } +); foreign_enum!( /// Supported score modes. enum ScoreMode { @@ -247,7 +262,7 @@ foreign_class!( /// Defaults to 0.5, wakeword defined value takes prevalence if present. fn RustpotterBuilder::setThreshold(&mut self, value: f32); /// Configures the detector averaged threshold, - /// is the min averaged score (in range 0. to 1.) + /// is the min averaged score (in range 0. to 1.) /// that a wakeword should obtain. /// When using wakeword references this prevent most computation. /// If set to 0. this functionality is disabled. @@ -261,11 +276,15 @@ foreign_class!( fn RustpotterBuilder::setMinScores(&mut self, value: usize); /// Configures the score operation to unify the score values /// against each wakeword template. - /// + /// /// Doesn't apply to trained wakewords. /// /// Defaults to max fn RustpotterBuilder::setScoreMode(&mut self, value: ScoreMode); + /// Enables a basic voice activity detector to prevent some execution. + /// + /// Disabled by default. + fn RustpotterBuilder::setVADMode(&mut self, value: Option); /// Configures the detector expected sample rate for the audio chunks to process. /// /// Defaults to 16000 @@ -286,7 +305,7 @@ foreign_class!( /// Configures the band-size for the comparator used to match the samples. /// /// Doesn't apply to trained wakewords. - /// + /// /// Defaults to 6 fn RustpotterBuilder::setBandSize(&mut self, value: u16); /// Value used to express the score in range 0 - 1. @@ -354,13 +373,13 @@ foreign_class!( /// Process audio chunks in bytes. /// /// The provided byte buffer length should match the return of the getBytesPerFrame method. - /// + /// /// The samples will be encoded used the configured endianness. fn Rustpotter::processBytes(&mut self, bytes: &[u8]) -> Option; - /// Loads a wakeword from its model path. - fn Rustpotter::addWakewordModelFile(&mut self, path: String) -> Result<(), String>; - /// Loads a wakeword from its model bytes. - fn Rustpotter::addWakewordModelBytes(&mut self, bytes: &[u8]) -> Result<(), String>; + /// Loads a wakeword from its file path. + fn Rustpotter::addWakewordFile(&mut self, path: String) -> Result<(), String>; + /// Loads a wakeword from its file bytes. + fn Rustpotter::addWakewordBytes(&mut self, bytes: &[u8]) -> Result<(), String>; /// Returns the desired chunk size. fn Rustpotter::getSamplesPerFrame(&self) -> usize; /// Returns size in bytes for the desired chunk. diff --git a/pom.xml b/pom.xml index 46643e4..0ac3adb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.givimad rustpotter-java - 3.0.0-beta.4 + 3.0.0-beta.5 rustpotter-java https://github.com/GiviMAD/rustpotter-java diff --git a/src/main/java/io/github/givimad/rustpotter_java/Rustpotter.java b/src/main/java/io/github/givimad/rustpotter_java/Rustpotter.java index 023dab7..c3c04a4 100644 --- a/src/main/java/io/github/givimad/rustpotter_java/Rustpotter.java +++ b/src/main/java/io/github/givimad/rustpotter_java/Rustpotter.java @@ -78,19 +78,19 @@ public final java.util.Optional processBytes(byte [] bytes) } private static native long do_processBytes(long self, byte [] bytes); /** - * Loads a wakeword from its model path. + * Loads a wakeword from its file path. */ - public final void addWakewordModelFile(String path) throws Exception { - do_addWakewordModelFile(mNativeObj, path); + public final void addWakewordFile(String path) throws Exception { + do_addWakewordFile(mNativeObj, path); } - private static native void do_addWakewordModelFile(long self, String path) throws Exception; + private static native void do_addWakewordFile(long self, String path) throws Exception; /** - * Loads a wakeword from its model bytes. + * Loads a wakeword from its file bytes. */ - public final void addWakewordModelBytes(byte [] bytes) throws Exception { - do_addWakewordModelBytes(mNativeObj, bytes); + public final void addWakewordBytes(byte [] bytes) throws Exception { + do_addWakewordBytes(mNativeObj, bytes); } - private static native void do_addWakewordModelBytes(long self, byte [] bytes) throws Exception; + private static native void do_addWakewordBytes(long self, byte [] bytes) throws Exception; /** * Returns the desired chunk size. */ diff --git a/src/main/java/io/github/givimad/rustpotter_java/RustpotterBuilder.java b/src/main/java/io/github/givimad/rustpotter_java/RustpotterBuilder.java index 80afd10..cdec778 100644 --- a/src/main/java/io/github/givimad/rustpotter_java/RustpotterBuilder.java +++ b/src/main/java/io/github/givimad/rustpotter_java/RustpotterBuilder.java @@ -58,6 +58,19 @@ public final void setScoreMode(ScoreMode value) { JNIReachabilityFence.reachabilityFence1(value); } private static native void do_setScoreMode(long self, int value); + /** + * Enables a basic voice activity detector to prevent some execution. + * + * Disabled by default. + */ + public final void setVADMode(VADMode value) { + int a0 = (value != null) ? value.getValue() : -1; + + do_setVADMode(mNativeObj, a0); + + JNIReachabilityFence.reachabilityFence1(value); + } + private static native void do_setVADMode(long self, int value); /** * Configures the detector expected sample rate for the audio chunks to process. * diff --git a/src/main/java/io/github/givimad/rustpotter_java/VADMode.java b/src/main/java/io/github/givimad/rustpotter_java/VADMode.java new file mode 100644 index 0000000..1114f85 --- /dev/null +++ b/src/main/java/io/github/givimad/rustpotter_java/VADMode.java @@ -0,0 +1,25 @@ +// Automatically generated by flapigen +package io.github.givimad.rustpotter_java; + +/** + * Supported vad modes. + */ +public enum VADMode { + EASY(0), + MEDIUM(1), + HARD(2); + + private final int value; + VADMode(int value) { + this.value = value; + } + public final int getValue() { return value; } + /*package*/ static VADMode fromInt(int x) { + switch (x) { + case 0: return EASY; + case 1: return MEDIUM; + case 2: return HARD; + default: throw new Error("Invalid value for enum VADMode: " + x); + } + } +}