diff --git a/binding/android/Koala/koala/build.gradle b/binding/android/Koala/koala/build.gradle index 0f58d1d..38613e6 100644 --- a/binding/android/Koala/koala/build.gradle +++ b/binding/android/Koala/koala/build.gradle @@ -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' } @@ -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") } diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/Koala.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/Koala.java index c604fa0..47413ff 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/Koala.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/Koala.java @@ -27,6 +27,7 @@ public class Koala { private static String defaultModelPath; + private static String _sdk = "android"; static { System.loadLibrary("pv_koala"); @@ -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); } diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/KoalaNative.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/KoalaNative.java index c954efa..1984f6b 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/KoalaNative.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/KoalaNative.java @@ -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); diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationException.java index 1b3138d..ea00b96 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaActivationException(Throwable cause) { public KoalaActivationException(String message) { super(message); } -} + public KoalaActivationException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationLimitException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationLimitException.java index c04c005..be4fc75 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationLimitException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationLimitException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaActivationLimitException(Throwable cause) { public KoalaActivationLimitException(String message) { super(message); } -} + public KoalaActivationLimitException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationRefusedException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationRefusedException.java index d9ff09e..050ebdf 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationRefusedException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationRefusedException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaActivationRefusedException(Throwable cause) { public KoalaActivationRefusedException(String message) { super(message); } -} + public KoalaActivationRefusedException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationThrottledException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationThrottledException.java index b50d1a5..75dc5bb 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationThrottledException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaActivationThrottledException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaActivationThrottledException(Throwable cause) { public KoalaActivationThrottledException(String message) { super(message); } -} + public KoalaActivationThrottledException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaException.java index 6042dd4..48acd6a 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaException.java @@ -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 @@ -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(); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaIOException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaIOException.java index ba2b3e0..82f6de5 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaIOException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaIOException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaIOException(Throwable cause) { public KoalaIOException(String message) { super(message); } -} + public KoalaIOException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaInvalidArgumentException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaInvalidArgumentException.java index 4abc938..e894805 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaInvalidArgumentException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaInvalidArgumentException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaInvalidArgumentException(Throwable cause) { public KoalaInvalidArgumentException(String message) { super(message); } -} + public KoalaInvalidArgumentException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaInvalidStateException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaInvalidStateException.java index 9d80896..66b9b7c 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaInvalidStateException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaInvalidStateException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaInvalidStateException(Throwable cause) { public KoalaInvalidStateException(String message) { super(message); } -} + public KoalaInvalidStateException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaKeyException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaKeyException.java index 5215661..bc07601 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaKeyException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaKeyException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaKeyException(Throwable cause) { public KoalaKeyException(String message) { super(message); } -} + public KoalaKeyException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaMemoryException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaMemoryException.java index b5d7a63..80ea292 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaMemoryException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaMemoryException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaMemoryException(Throwable cause) { public KoalaMemoryException(String message) { super(message); } -} + public KoalaMemoryException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaRuntimeException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaRuntimeException.java index d1dba66..8ee1652 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaRuntimeException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaRuntimeException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaRuntimeException(Throwable cause) { public KoalaRuntimeException(String message) { super(message); } -} + public KoalaRuntimeException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaStopIterationException.java b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaStopIterationException.java index 595d14d..e6bc0ac 100644 --- a/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaStopIterationException.java +++ b/binding/android/Koala/koala/src/main/java/ai/picovoice/koala/exception/KoalaStopIterationException.java @@ -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 @@ -18,5 +20,8 @@ public KoalaStopIterationException(Throwable cause) { public KoalaStopIterationException(String message) { super(message); } -} + public KoalaStopIterationException(String message, String[] messageStack) { + super(message, messageStack); + } +} diff --git a/binding/android/KoalaTestApp/build.gradle b/binding/android/KoalaTestApp/build.gradle index 9e877c5..c6130a9 100644 --- a/binding/android/KoalaTestApp/build.gradle +++ b/binding/android/KoalaTestApp/build.gradle @@ -20,6 +20,9 @@ allprojects { repositories { google() mavenCentral() + maven { + url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1277/' + } } } diff --git a/binding/android/KoalaTestApp/koala-test-app/build.gradle b/binding/android/KoalaTestApp/koala-test-app/build.gradle index fbe2c9a..f41fde6 100644 --- a/binding/android/KoalaTestApp/koala-test-app/build.gradle +++ b/binding/android/KoalaTestApp/koala-test-app/build.gradle @@ -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' diff --git a/binding/android/KoalaTestApp/koala-test-app/src/androidTest/java/ai/picovoice/koala/testapp/KoalaTest.java b/binding/android/KoalaTestApp/koala-test-app/src/androidTest/java/ai/picovoice/koala/testapp/KoalaTest.java index fa10921..b2be5df 100644 --- a/binding/android/KoalaTestApp/koala-test-app/src/androidTest/java/ai/picovoice/koala/testapp/KoalaTest.java +++ b/binding/android/KoalaTestApp/koala-test-app/src/androidTest/java/ai/picovoice/koala/testapp/KoalaTest.java @@ -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); diff --git a/demo/android/Activity/build.gradle b/demo/android/Activity/build.gradle index 9e877c5..c6130a9 100644 --- a/demo/android/Activity/build.gradle +++ b/demo/android/Activity/build.gradle @@ -20,6 +20,9 @@ allprojects { repositories { google() mavenCentral() + maven { + url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1277/' + } } } diff --git a/demo/android/Activity/koala-activity-demo-app/build.gradle b/demo/android/Activity/koala-activity-demo-app/build.gradle index 2e1efbb..1572f57 100644 --- a/demo/android/Activity/koala-activity-demo-app/build.gradle +++ b/demo/android/Activity/koala-activity-demo-app/build.gradle @@ -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' } diff --git a/demo/android/Activity/koala-activity-demo-app/src/main/java/ai/picovoice/koalaactivitydemo/MainActivity.java b/demo/android/Activity/koala-activity-demo-app/src/main/java/ai/picovoice/koalaactivitydemo/MainActivity.java index 090c220..596c2ab 100644 --- a/demo/android/Activity/koala-activity-demo-app/src/main/java/ai/picovoice/koalaactivitydemo/MainActivity.java +++ b/demo/android/Activity/koala-activity-demo-app/src/main/java/ai/picovoice/koalaactivitydemo/MainActivity.java @@ -89,7 +89,7 @@ protected void onCreate(Bundle savedInstanceState) { try { koala = new Koala.Builder().setAccessKey(ACCESS_KEY).build(getApplicationContext()); } catch (KoalaInvalidArgumentException e) { - onKoalaInitError(String.format("AccessKey '%s' is invalid", ACCESS_KEY)); + onKoalaInitError(e.getMessage()); } catch (KoalaActivationException e) { onKoalaInitError("AccessKey activation error"); } catch (KoalaActivationLimitException e) { diff --git a/resources/.lint/java/suppress.xml b/resources/.lint/java/suppress.xml index 290f2c2..02787ef 100644 --- a/resources/.lint/java/suppress.xml +++ b/resources/.lint/java/suppress.xml @@ -10,7 +10,7 @@ - +