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 #673

Merged
merged 8 commits into from
Oct 20, 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
18 changes: 18 additions & 0 deletions demo/android/Activity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ buildscript {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1266/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1267/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1269/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
Expand All @@ -17,6 +26,15 @@ allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1266/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1267/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1269/'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,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:picovoice-android:2.2.1'
implementation 'ai.picovoice:picovoice-android:3.0.0'
}

afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MainActivity extends AppCompatActivity {
private static final String ACCESS_KEY = "${YOUR_ACCESS_KEY_HERE}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)
private String wakeWordName = "";
private String contextName = "";
private String contextInformation = "";

private PicovoiceManager picovoiceManager;
private TextView intentTextView;
Expand Down Expand Up @@ -183,23 +184,33 @@ private void initPicovoice() {
rhinoModel = "rhino_params_" + BuildConfig.FLAVOR + ".pv";
}

picovoiceManager = new PicovoiceManager.Builder()
.setAccessKey(ACCESS_KEY)
.setKeywordPath("wakewords/" + wakeWordName.replace(" ", "_") + ".ppn")
.setPorcupineSensitivity(0.75f)
.setPorcupineModelPath("models/" + porcupineModel)
.setWakeWordCallback(picovoiceWakeWordCallback)
.setContextPath("contexts/" + contextName + ".rhn")
.setRhinoSensitivity(0.25f)
.setRhinoModelPath("models/" + rhinoModel)
.setInferenceCallback(picovoiceInferenceCallback)
.setProcessErrorCallback(picovoiceManagerErrorCallback)
.build(getApplicationContext());

try {
Log.i("PicovoiceManager", picovoiceManager.getContextInformation());
picovoiceManager = new PicovoiceManager.Builder()
.setAccessKey(ACCESS_KEY)
.setKeywordPath("wakewords/" + wakeWordName.replace(" ", "_") + ".ppn")
.setPorcupineSensitivity(0.75f)
.setPorcupineModelPath("models/" + porcupineModel)
.setWakeWordCallback(picovoiceWakeWordCallback)
.setContextPath("contexts/" + contextName + ".rhn")
.setRhinoSensitivity(0.25f)
.setRhinoModelPath("models/" + rhinoModel)
.setInferenceCallback(picovoiceInferenceCallback)
.setProcessErrorCallback(picovoiceManagerErrorCallback)
.build(getApplicationContext());
contextInformation = picovoiceManager.getContextInformation();
Log.i("PicovoiceManager", contextInformation);
} catch (PicovoiceInvalidArgumentException e) {
onPicovoiceError(e.getMessage());
} catch (PicovoiceActivationException e) {
onPicovoiceError("AccessKey activation error");
} catch (PicovoiceActivationLimitException e) {
onPicovoiceError("AccessKey reached its device limit");
} catch (PicovoiceActivationRefusedException e) {
onPicovoiceError("AccessKey refused");
} catch (PicovoiceActivationThrottledException e) {
onPicovoiceError("AccessKey has been throttled");
} catch (PicovoiceException e) {
Log.e("PicovoiceManager", "Failed to get context info: \n" + e);
onPicovoiceError("Failed to initialize Picovoice " + e.getMessage());
}
}

Expand All @@ -219,49 +230,12 @@ public void process(View view) {
picovoiceManager.stop();
intentTextView.setText("");
}
} catch (PicovoiceInvalidArgumentException e) {
onPicovoiceError(
String.format(
"%s\nEnsure your AccessKey '%s' is a valid access key.",
e.getLocalizedMessage(),
ACCESS_KEY));
} catch (PicovoiceActivationException e) {
onPicovoiceError("AccessKey activation error");
} catch (PicovoiceActivationLimitException e) {
onPicovoiceError("AccessKey reached its device limit");
} catch (PicovoiceActivationRefusedException e) {
onPicovoiceError("AccessKey refused");
} catch (PicovoiceActivationThrottledException e) {
onPicovoiceError("AccessKey has been throttled");
} catch (PicovoiceException e) {
onPicovoiceError("Failed to initialize Picovoice " + e.getMessage());
Log.e("PicovoiceManager", e.getMessage());
}
}

public void showContextCheatSheet(View view) {
String contextInformation;
try {
contextInformation = picovoiceManager.getContextInformation();
} catch (PicovoiceException e) {
Log.e("PicovoiceManager", "Failed to get context info: \n" + e);
return;
}

if (contextInformation.equals("")) {
if (!hasRecordPermission()) {
requestRecordPermission(1);
return;
}
try {
picovoiceManager.start();
contextInformation = picovoiceManager.getContextInformation();
picovoiceManager.stop();
} catch (PicovoiceException e) {
onPicovoiceError(e.getMessage());
return;
}
}

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
ViewGroup viewGroup = findViewById(R.id.content);
View dialogView = LayoutInflater.from(view.getContext())
Expand Down
18 changes: 18 additions & 0 deletions demo/android/Service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ buildscript {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1266/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1267/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1269/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
Expand All @@ -17,6 +26,15 @@ allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1266/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1267/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1269/'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'ai.picovoice:picovoice-android:2.2.1'
implementation 'ai.picovoice:picovoice-android:3.0.0'
}

task copyPorcupineResources(type: Copy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
picovoiceManager.start();
started = true;
} catch (PicovoiceInvalidArgumentException e) {
onPicovoiceError(
String.format(
"%s\nEnsure your AccessKey '%s' is a valid access key.",
e.getLocalizedMessage(),
ACCESS_KEY));
onPicovoiceError(e.getMessage());
} catch (PicovoiceActivationException e) {
onPicovoiceError("AccessKey activation error");
} catch (PicovoiceActivationLimitException e) {
Expand All @@ -120,7 +116,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
} catch (PicovoiceActivationThrottledException e) {
onPicovoiceError("AccessKey has been throttled");
} catch (PicovoiceException e) {
onPicovoiceError("Failed to initialize Picovoice " + e.getMessage());
onPicovoiceError("Failed to initialize Picovoice: " + e.getMessage());
}

Notification notification = started ?
Expand Down
16 changes: 14 additions & 2 deletions sdk/android/Picovoice/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1266/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1267/'
}
}

dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath "ai.picovoice:porcupine-android:2.2.2"
classpath "ai.picovoice:rhino-android:2.2.2"
classpath "ai.picovoice:porcupine-android:3.0.0"
classpath "ai.picovoice:rhino-android:3.0.0"
classpath "ai.picovoice:android-voice-processor:1.0.2"
}
}
Expand All @@ -22,6 +28,12 @@ allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1266/'
}
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1267/'
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/android/Picovoice/picovoice/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.1'
PUBLISH_VERSION = '3.0.0'
PUBLISH_ARTIFACT_ID = 'picovoice-android'
}
android {
Expand Down Expand Up @@ -34,7 +34,7 @@ if (file("${rootDir}/publish-mavencentral.gradle").exists()) {
}

dependencies {
implementation 'ai.picovoice:porcupine-android:2.2.2'
implementation 'ai.picovoice:rhino-android:2.2.2'
implementation 'ai.picovoice:porcupine-android:3.0.0'
implementation 'ai.picovoice:rhino-android:3.0.0'
implementation 'ai.picovoice:android-voice-processor:1.0.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ private Picovoice(
PicovoiceWakeWordCallback wakeWordCallback,
Rhino rhino,
PicovoiceInferenceCallback inferenceCallback) {

this.porcupine = porcupine;
this.wakeWordCallback = wakeWordCallback;
this.rhino = rhino;
this.inferenceCallback = inferenceCallback;
}

/**
* Releases resources acquired.
* Releases resources acquired by Picovoice.
*/
public void delete() {
if (porcupine != null) {
Expand Down Expand Up @@ -135,13 +134,28 @@ public void run() {
}
}

/**
* Resets the internal state of Picovoice. It should be called before processing a new stream of audio
* or when process was stopped while processing a stream of audio.
*
* @throws PicovoiceException if reset fails.
*/
public void reset() throws PicovoiceException {
try {
this.isWakeWordDetected = false;
this.rhino.reset();
} catch (RhinoException e) {
throw mapToPicovoiceException(e);
}
}

/**
* Getter for version.
*
* @return Version.
*/
public String getVersion() {
return "2.2.0";
return "3.0.0";
}

/**
Expand Down Expand Up @@ -389,9 +403,9 @@ public Picovoice build(Context appContext) throws PicovoiceException {
.setSensitivity(porcupineSensitivity)
.build(appContext);

if (!porcupine.getVersion().startsWith("2.2.")) {
if (!porcupine.getVersion().startsWith("3.0.")) {
final String message = String.format(
"Expected Porcupine library with version '2.2.x' but received %s",
"Expected Porcupine library with version '3.0.x' but received %s",
porcupine.getVersion());
throw new PicovoiceRuntimeException(message);
}
Expand All @@ -405,9 +419,9 @@ public Picovoice build(Context appContext) throws PicovoiceException {
.setRequireEndpoint(requireEndpoint)
.build(appContext);

if (!rhino.getVersion().startsWith("2.2.")) {
if (!rhino.getVersion().startsWith("3.0.")) {
final String message = String.format(
"Expected Rhino library with version '2.2.x' but received %s",
"Expected Rhino library with version '3.0.x' but received %s",
rhino.getVersion());
throw new PicovoiceRuntimeException(message);
}
Expand Down
Loading