Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0 android #586

Merged
merged 12 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion binding/android/Rhino/rhino/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 = '2.2.2'
PUBLISH_VERSION = '3.0.0'
PUBLISH_ARTIFACT_ID = 'rhino-android'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018-2022 Picovoice Inc.
Copyright 2018-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
Expand Down Expand Up @@ -34,6 +34,7 @@ public class Rhino {

private static String DEFAULT_MODEL_PATH;
private static boolean isExtracted;
private static String _sdk = "android";

static {
System.loadLibrary("pv_rhino");
Expand All @@ -42,6 +43,10 @@ public class Rhino {
private long handle;
private boolean isFinalized;

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

/**
* Constructor.
*
Expand Down Expand Up @@ -72,6 +77,8 @@ private Rhino(String accessKey,
float sensitivity,
float endpointDurationSec,
boolean requireEndpoint) throws RhinoException {
RhinoNative.setSdk(Rhino._sdk);

handle = RhinoNative.init(
accessKey,
modelPath,
Expand Down Expand Up @@ -121,6 +128,20 @@ public boolean process(short[] pcm) throws RhinoException {
return isFinalized;
}

/**
* Resets the internal state of Rhino. It should be called before the engine can be
* used to infer intent from a new stream of audio.
*
* @throws RhinoException if reset fails.
*/
public void reset() throws RhinoException {
if (handle == 0) {
throw new RhinoInvalidStateException("Attempted to call Rhino reset after delete.");
}

RhinoNative.reset(handle);
}

/**
* Gets inference result from Rhino. If the spoken command was understood, it includes the
* specific intent name that was inferred, and (if applicable) slot keys and specific slot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,8 @@
package ai.picovoice.rhino;

import android.content.Context;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.util.Log;

import java.util.concurrent.Callable;
import java.util.concurrent.Executors;

import ai.picovoice.android.voiceprocessor.VoiceProcessor;
import ai.picovoice.android.voiceprocessor.VoiceProcessorErrorListener;
import ai.picovoice.android.voiceprocessor.VoiceProcessorException;
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,6 +20,8 @@ class RhinoNative {

static native String getVersion();

static native void setSdk(String sdk);

static native long init(
String accessKey,
String modelPath,
Expand All @@ -32,6 +34,8 @@ static native long init(

static native boolean process(long object, short[] pcm) throws RhinoException;

static native void reset(long object) throws RhinoException;

static native RhinoInference getInference(long object) throws RhinoException;

static native String getContextInfo(long object) throws RhinoException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoActivationException(Throwable cause) {
public RhinoActivationException(String message) {
super(message);
}

public RhinoActivationException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoActivationLimitException(Throwable cause) {
public RhinoActivationLimitException(String message) {
super(message);
}
}

public RhinoActivationLimitException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoActivationRefusedException(Throwable cause) {
public RhinoActivationRefusedException(String message) {
super(message);
}
}

public RhinoActivationRefusedException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoActivationThrottledException(Throwable cause) {
public RhinoActivationThrottledException(String message) {
super(message);
}
}

public RhinoActivationThrottledException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
/*
Copyright 2018-2021 Picovoice Inc.
Copyright 2021-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
limitations under the License.
*/


package ai.picovoice.rhino;

public class RhinoException extends Exception {
RhinoException(Throwable cause) {
private final String message;
private final String[] messageStack;

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

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

public RhinoException(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 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoIOException(Throwable cause) {
public RhinoIOException(String message) {
super(message);
}
}

public RhinoIOException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoInvalidArgumentException(Throwable cause) {
public RhinoInvalidArgumentException(String message) {
super(message);
}
}

public RhinoInvalidArgumentException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoInvalidStateException(Throwable cause) {
public RhinoInvalidStateException(String message) {
super(message);
}
}

public RhinoInvalidStateException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoKeyException(Throwable cause) {
public RhinoKeyException(String message) {
super(message);
}
}

public RhinoKeyException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoMemoryException(Throwable cause) {
public RhinoMemoryException(String message) {
super(message);
}
}

public RhinoMemoryException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoRuntimeException(Throwable cause) {
public RhinoRuntimeException(String message) {
super(message);
}
}

public RhinoRuntimeException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Picovoice Inc.
Copyright 2021-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
Expand All @@ -18,4 +18,8 @@ public RhinoStopIterationException(Throwable cause) {
public RhinoStopIterationException(String message) {
super(message);
}
}

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

dependencies {
Expand All @@ -24,6 +27,9 @@ allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1267/'
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion binding/android/RhinoTestApp/rhino-test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.code.gson:gson:2.10'
implementation 'ai.picovoice:rhino-android:2.2.2'
implementation 'ai.picovoice:rhino-android:3.0.0'

// Espresso UI Testing
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
Loading