Skip to content

Commit

Permalink
v2.0 android (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 authored Nov 1, 2023
1 parent aaed1db commit bb2151e
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 21 deletions.
6 changes: 3 additions & 3 deletions binding/android/Koala/koala/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 = '1.0.0'
PUBLISH_VERSION = '2.0.0'
PUBLISH_ARTIFACT_ID = 'koala-android'
}

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

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

task copyParams(type: Copy) {
from("${rootDir}/../../lib/common")
from("${rootDir}/../../../lib/common")
into("${rootDir}/koala/src/main/res/raw")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
public class Koala {

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

static {
System.loadLibrary("pv_koala");
Expand All @@ -43,6 +44,7 @@ public class Koala {
* @throws KoalaException if there is an error while initializing Koala.
*/
private Koala(String accessKey, String modelPath) throws KoalaException {
KoalaNative.setSdk(Koala._sdk);
handle = KoalaNative.init(accessKey, modelPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

class KoalaNative {

static native int getSampleRate();

static native String getVersion();

static native int getFrameLength();

static native int getSampleRate();

static native void setSdk(String sdk);

static native long init(String accessKey, String modelPath) throws KoalaException;

static native void delete(long object);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaActivationException(Throwable cause) {
public KoalaActivationException(String message) {
super(message);
}
}

public KoalaActivationException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaActivationLimitException(Throwable cause) {
public KoalaActivationLimitException(String message) {
super(message);
}
}

public KoalaActivationLimitException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaActivationRefusedException(Throwable cause) {
public KoalaActivationRefusedException(String message) {
super(message);
}
}

public KoalaActivationRefusedException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaActivationThrottledException(Throwable cause) {
public KoalaActivationThrottledException(String message) {
super(message);
}
}

public KoalaActivationThrottledException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -11,12 +13,42 @@
package ai.picovoice.koala;

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

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

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

public KoalaException(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,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaIOException(Throwable cause) {
public KoalaIOException(String message) {
super(message);
}
}

public KoalaIOException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaInvalidArgumentException(Throwable cause) {
public KoalaInvalidArgumentException(String message) {
super(message);
}
}

public KoalaInvalidArgumentException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaInvalidStateException(Throwable cause) {
public KoalaInvalidStateException(String message) {
super(message);
}
}

public KoalaInvalidStateException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaKeyException(Throwable cause) {
public KoalaKeyException(String message) {
super(message);
}
}

public KoalaKeyException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaMemoryException(Throwable cause) {
public KoalaMemoryException(String message) {
super(message);
}
}

public KoalaMemoryException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaRuntimeException(Throwable cause) {
public KoalaRuntimeException(String message) {
super(message);
}
}

public KoalaRuntimeException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/*
Copyright 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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
Expand All @@ -18,5 +20,8 @@ public KoalaStopIterationException(Throwable cause) {
public KoalaStopIterationException(String message) {
super(message);
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion binding/android/KoalaTestApp/koala-test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'ai.picovoice:koala-android:1.0.0'
implementation 'ai.picovoice:koala-android:2.0.0'

// Espresso UI Testing
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,31 @@ private void extractAssetsRecursively(String path) throws IOException {
}
}

@Test
public void testErrorStack() {
String[] error = {};
try {
new Koala.Builder()
.setAccessKey("invalid")
.build(getApplicationContext());
} catch (KoalaException e) {
error = e.getMessageStack();
}

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

try {
new Koala.Builder()
.setAccessKey("invalid")
.build(getApplicationContext());
} catch (KoalaException e) {
for (int i = 0; i < error.length; i++) {
assertEquals(e.getMessageStack()[i], error[i]);
}
}
}

private void extractTestFile(String filepath) throws IOException {

InputStream is = new BufferedInputStream(assetManager.open(filepath), 256);
Expand Down
3 changes: 3 additions & 0 deletions demo/android/Activity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1277/'
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion demo/android/Activity/koala-activity-demo-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
implementation 'androidx.navigation:navigation-ui:2.3.5'
implementation 'ai.picovoice:koala-android:1.0.0'
implementation 'ai.picovoice:koala-android:2.0.0'
implementation 'ai.picovoice:android-voice-processor:1.0.2'
}
Loading

0 comments on commit bb2151e

Please sign in to comment.