Skip to content

Commit

Permalink
use beta-5
Browse files Browse the repository at this point in the history
  • Loading branch information
GiviMAD committed Aug 29, 2023
1 parent 1f9ea5e commit 212c7e9
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 39 deletions.
22 changes: 11 additions & 11 deletions binding/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions binding/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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."

Expand All @@ -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"
Expand Down
53 changes: 36 additions & 17 deletions binding/src/java_glue.rs.in
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<VADMode>) {
self.config.detector.vad_mode = value.into();
}
pub fn setSampleRate(&mut self, value: usize) {
self.config.fmt.sample_rate = value;
}
Expand Down Expand Up @@ -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<RustpotterDetection> {
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<RustpotterDetection> {
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<RustpotterDetection> {
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<RustpotterDetection> {
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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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<VADMode>);
/// Configures the detector expected sample rate for the audio chunks to process.
///
/// Defaults to 16000
Expand All @@ -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.
Expand Down Expand Up @@ -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<RustpotterDetection>;
/// 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.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.givimad</groupId>
<artifactId>rustpotter-java</artifactId>
<version>3.0.0-beta.4</version>
<version>3.0.0-beta.5</version>

<name>rustpotter-java</name>
<url>https://github.com/GiviMAD/rustpotter-java</url>
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/io/github/givimad/rustpotter_java/Rustpotter.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ public final java.util.Optional<RustpotterDetection> 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/io/github/givimad/rustpotter_java/VADMode.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 212c7e9

Please sign in to comment.