Skip to content

Commit

Permalink
v0.2 android
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 committed Nov 3, 2023
1 parent f9241be commit 1ab6121
Show file tree
Hide file tree
Showing 24 changed files with 133 additions and 9 deletions.
6 changes: 3 additions & 3 deletions binding/android/Eagle/eagle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

ext {
PUBLISH_GROUP_ID = 'ai.picovoice'
PUBLISH_VERSION = '0.1.1'
PUBLISH_VERSION = '0.2.0'
PUBLISH_ARTIFACT_ID = 'eagle-android'
}

Expand Down Expand Up @@ -34,12 +34,12 @@ dependencies {
}

task copyLibs(type: Copy) {
from("${rootDir}/../../lib/android")
from("${rootDir}/../../../lib/android")
into("${rootDir}/eagle/src/main/jniLibs")
}

task copyParams(type: Copy) {
from("${rootDir}/../../lib/common")
from("${rootDir}/../../../lib/common")
include('eagle_params.pv')
into("${rootDir}/eagle/src/main/res/raw")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class Eagle {

private static String defaultModelPath;
private static String _sdk = "android";

static {
System.loadLibrary("pv_eagle");
Expand All @@ -36,6 +37,10 @@ public class Eagle {
private long handle;
private int numSpeakers;

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

/**
* Constructor.
*
Expand All @@ -54,6 +59,7 @@ private Eagle(
profileHandles[i] = speakerProfiles[i].profileNative.handle;
}

EagleNative.setSdk(Eagle._sdk);
handle = EagleNative.init(
accessKey,
modelPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

class EagleNative {

static native String getVersion();

static native int getFrameLength();

static native int getSampleRate();

static native String getVersion();
static native void setSdk(String sdk);

static native long init(
String accessKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ public void delete() {

private native byte[] getBytesNative(long handle, int numBytes);

private native long setBytesNative(byte[] metadataBytes, int numBytes);
private native long setBytesNative(byte[] profileBytes, int numBytes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public class EagleProfiler {

private static String defaultModelPath;
private static String _sdk = "android";

private final int minEnrollSamples;

Expand All @@ -38,6 +39,10 @@ public class EagleProfiler {

private long handle;

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

/**
* Constructor.
*
Expand All @@ -46,6 +51,7 @@ public class EagleProfiler {
* @throws EagleException if there is an error while initializing EagleProfiler.
*/
private EagleProfiler(String accessKey, String modelPath) throws EagleException {
EagleNative.setSdk(EagleProfiler._sdk);
handle = EagleProfilerNative.init(accessKey, modelPath);
minEnrollSamples = EagleProfilerNative.minEnrollSamples(handle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleActivationException(Throwable cause) {
public EagleActivationException(String message) {
super(message);
}

public EagleActivationException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleActivationLimitException(Throwable cause) {
public EagleActivationLimitException(String message) {
super(message);
}

public EagleActivationLimitException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleActivationRefusedException(Throwable cause) {
public EagleActivationRefusedException(String message) {
super(message);
}

public EagleActivationRefusedException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleActivationThrottledException(Throwable cause) {
public EagleActivationThrottledException(String message) {
super(message);
}

public EagleActivationThrottledException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,44 @@
package ai.picovoice.eagle;

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

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

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

public EagleException(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]));
}
} else {
sb.append(".");
}
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleIOException(Throwable cause) {
public EagleIOException(String message) {
super(message);
}

public EagleIOException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleInvalidArgumentException(Throwable cause) {
public EagleInvalidArgumentException(String message) {
super(message);
}

public EagleInvalidArgumentException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleInvalidStateException(Throwable cause) {
public EagleInvalidStateException(String message) {
super(message);
}

public EagleInvalidStateException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleKeyException(Throwable cause) {
public EagleKeyException(String message) {
super(message);
}

public EagleKeyException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleMemoryException(Throwable cause) {
public EagleMemoryException(String message) {
super(message);
}

public EagleMemoryException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleRuntimeException(Throwable cause) {
public EagleRuntimeException(String message) {
super(message);
}

public EagleRuntimeException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public EagleStopIterationException(Throwable cause) {
public EagleStopIterationException(String message) {
super(message);
}

public EagleStopIterationException(String message, String[] messageStack) {
super(message, messageStack);
}
}
3 changes: 3 additions & 0 deletions binding/android/EagleTestApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1288/'
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion binding/android/EagleTestApp/eagle-test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'ai.picovoice:eagle-android:0.1.1'
implementation 'ai.picovoice:eagle-android:0.2.0'

// Espresso UI Testing
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,32 @@ public void testEagleProcessImposter() throws Exception {
assertTrue(Collections.max(scores) < 0.5);
eagle.delete();
}

@Test
public void testErrorStack() {
String[] error = {};
try {
new Eagle.Builder()
.setAccessKey("invalid")
.setSpeakerProfile(profile)
.build(appContext);
} catch (EagleException e) {
error = e.getMessageStack();
}

assertTrue(0 < error.length);
assertTrue(error.length <= 8);

try {
new Eagle.Builder()
.setAccessKey("invalid")
.setSpeakerProfile(profile)
.build(appContext);
} catch (EagleException e) {
for (int i = 0; i < error.length; i++) {
assertEquals(e.getMessageStack()[i], error[i]);
}
}
}
}
}
3 changes: 3 additions & 0 deletions demo/android/EagleDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1288/'
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion demo/android/EagleDemo/eagle-demo-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'ai.picovoice:eagle-android:0.1.1'
implementation 'ai.picovoice:eagle-android:0.2.0'
implementation 'ai.picovoice:android-voice-processor:1.0.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void setUIState(UIState state) {

private void handleEagleException(EagleException e) {
if (e instanceof EagleInvalidArgumentException) {
displayError(String.format("%s\nEnsure your AccessKey '%s' is valid", e.getMessage(), ACCESS_KEY));
displayError(String.format(e.getMessage());
} else if (e instanceof EagleActivationException) {
displayError("AccessKey activation error");
} else if (e instanceof EagleActivationLimitException) {
Expand Down
2 changes: 1 addition & 1 deletion resources/.lint/java/suppress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<suppress files=".*(Test|Exception|Callback|demo|Module|Plugin|Package).*\.java" checks="MissingJavadocType"/>
<suppress files=".*(Test|Exception|Error|demo).*\.java" checks="OneTopLevelClass"/>
<suppress files=".*(Test).*\.java" checks="MethodName"/>
<suppress files=".*(demo|Module|Plugin).*\.java" checks="MissingJavadocMethod"/>
<suppress files=".*(demo|Module|Plugin|Exception).*\.java" checks="MissingJavadocMethod"/>
<suppress files=".*generated-sources.*" checks="[a-zA-Z0-9]*"/>
<suppress files=".*build.*" checks="[a-zA-Z0-9]*"/>
<suppress files=".*" checks="CustomImportOrder"/>
Expand Down

0 comments on commit 1ab6121

Please sign in to comment.