Skip to content

Commit

Permalink
v2.0 java (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
laves authored Nov 23, 2023
1 parent df84ff7 commit db5ec4e
Show file tree
Hide file tree
Showing 23 changed files with 172 additions and 42 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/java-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
java-version: ['11', '17', '19']

steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: ${{ matrix.java-version }}
distribution: 'temurin'

- name: Build
Expand Down
34 changes: 17 additions & 17 deletions .github/workflows/java-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
init_performance_threshold_sec: 2.0
proc_performance_threshold_sec: 0.5
- os: windows-latest
init_performance_threshold_sec: 2.1
proc_performance_threshold_sec: 0.6
init_performance_threshold_sec: 4.5
proc_performance_threshold_sec: 1.0
- os: macos-latest
init_performance_threshold_sec: 2.5
proc_performance_threshold_sec: 0.7
init_performance_threshold_sec: 5.5
proc_performance_threshold_sec: 3.0
- os: windows-latest
init_performance_threshold_sec: 4.5
proc_performance_threshold_sec: 1.0

steps:
- uses: actions/checkout@v3
Expand All @@ -64,20 +64,20 @@ jobs:
machine: [rpi3-32, rpi3-64, rpi4-32, rpi4-64, jetson]
include:
- machine: rpi3-32
init_performance_threshold_sec: 7.5
proc_performance_threshold_sec: 3.3
init_performance_threshold_sec: 14.0
proc_performance_threshold_sec: 9.3
- machine: rpi3-64
init_performance_threshold_sec: 8.8
proc_performance_threshold_sec: 3.3
init_performance_threshold_sec: 13.5
proc_performance_threshold_sec: 8.3
- machine: rpi4-32
init_performance_threshold_sec: 5.6
proc_performance_threshold_sec: 2.0
init_performance_threshold_sec: 8.5
proc_performance_threshold_sec: 4.6
- machine: rpi4-64
init_performance_threshold_sec: 5.1
proc_performance_threshold_sec: 1.9
init_performance_threshold_sec: 7.8
proc_performance_threshold_sec: 5.0
- machine: jetson
init_performance_threshold_sec: 5.1
proc_performance_threshold_sec: 2.0
init_performance_threshold_sec: 7.8
proc_performance_threshold_sec: 5.5

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
java-version: ['11', '17', '19']

steps:
- uses: actions/checkout@v3

- name: Set up JDK 11
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: ${{ matrix.java-version }}
distribution: 'temurin'

- name: Build
Expand Down
2 changes: 1 addition & 1 deletion binding/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

ext {
PUBLISH_GROUP_ID = 'ai.picovoice'
PUBLISH_VERSION = '1.1.1'
PUBLISH_VERSION = '2.0.0'
PUBLISH_ARTIFACT_ID = 'cheetah-java'
}

Expand Down
2 changes: 1 addition & 1 deletion binding/java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 8 additions & 0 deletions binding/java/src/ai/picovoice/cheetah/Cheetah.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
public class Cheetah {

private static String sdk = "java";

public static final String LIBRARY_PATH;
public static final String MODEL_PATH;

Expand All @@ -27,6 +29,10 @@ public class Cheetah {
MODEL_PATH = Utils.getPackagedModelPath();
}

public static void setSdk(String sdk) {
Cheetah.sdk = sdk;
}

private long handle;

/**
Expand All @@ -53,6 +59,8 @@ private Cheetah(
} catch (Exception exception) {
throw new CheetahException(exception);
}
CheetahNative.setSdk(Cheetah.sdk);

handle = CheetahNative.init(
accessKey,
modelPath,
Expand Down
2 changes: 2 additions & 0 deletions binding/java/src/ai/picovoice/cheetah/CheetahNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class CheetahNative {

static native String getVersion();

static native void setSdk(String sdk);

static native long init(
String accessKey,
String modelPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahActivationException(Throwable cause) {
public CheetahActivationException(String message) {
super(message);
}

public CheetahActivationException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahActivationLimitException(Throwable cause) {
public CheetahActivationLimitException(String message) {
super(message);
}

public CheetahActivationLimitException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahActivationRefusedException(Throwable cause) {
public CheetahActivationRefusedException(String message) {
super(message);
}

public CheetahActivationRefusedException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahActivationThrottledException(Throwable cause) {
public CheetahActivationThrottledException(String message) {
super(message);
}

public CheetahActivationThrottledException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -13,11 +13,42 @@
package ai.picovoice.cheetah;

public class CheetahException extends Exception {
private final String message;
private final String[] messageStack;

public CheetahException(Throwable cause) {
super(cause);
this.message = cause.getMessage();
this.messageStack = null;
}

public CheetahException(String message) {
super(message);
this.message = message;
this.messageStack = null;
}

public CheetahException(String message, String[] messageStack) {
super(message);
this.message = message;
this.messageStack = messageStack;
}

public String[] getMessageStack() {
return this.messageStack;
}

@Override
public String getMessage() {
StringBuilder sb = new StringBuilder(message);
if (messageStack != null) {
if (messageStack.length > 0) {
sb.append(":");
for (int i = 0; i < messageStack.length; i++) {
sb.append(String.format("\n [%d] %s", i, messageStack[i]));
}
}
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahIOException(Throwable cause) {
public CheetahIOException(String message) {
super(message);
}

public CheetahIOException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahInvalidArgumentException(Throwable cause) {
public CheetahInvalidArgumentException(String message) {
super(message);
}

public CheetahInvalidArgumentException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahInvalidStateException(Throwable cause) {
public CheetahInvalidStateException(String message) {
super(message);
}

public CheetahInvalidStateException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahKeyException(Throwable cause) {
public CheetahKeyException(String message) {
super(message);
}

public CheetahKeyException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahMemoryException(Throwable cause) {
public CheetahMemoryException(String message) {
super(message);
}

public CheetahMemoryException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahRuntimeException(Throwable cause) {
public CheetahRuntimeException(String message) {
super(message);
}

public CheetahRuntimeException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is
located in the "LICENSE" file accompanying this source.
Expand All @@ -20,4 +20,8 @@ public CheetahStopIterationException(Throwable cause) {
public CheetahStopIterationException(String message) {
super(message);
}

public CheetahStopIterationException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class CheetahPerformanceTest {

@Test
void initPerformance() throws Exception {

long[] perfResults = new long[numTestIterations];
for (int i = 0; i < numTestIterations + 1; i++) {
long before = System.nanoTime();
Expand Down
Loading

0 comments on commit db5ec4e

Please sign in to comment.