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

v2.0 android #175

Merged
merged 5 commits into from
Oct 25, 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
35 changes: 35 additions & 0 deletions .github/workflows/android-demos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Android Demos

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- '.github/workflows/android-demos.yml'
- 'demo/android/**'
- '!demo/android/Activity/README.md'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '.github/workflows/android-demos.yml'
- 'demo/android/**'
- '!demo/android/Activity/README.md'

jobs:
build-activity-demo:
runs-on: ubuntu-latest
defaults:
run:
working-directory: demo/android/Activity

steps:
- uses: actions/checkout@v3

- name: set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'

- name: Build
run: ./gradlew assembleDebug
3 changes: 0 additions & 3 deletions binding/android/Cobra/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext {
defaultTargetSdkVersion = 31
}
Expand All @@ -11,8 +10,6 @@ buildscript {
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

Expand Down
12 changes: 3 additions & 9 deletions binding/android/Cobra/cobra/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ apply plugin: 'com.android.library'

ext {
PUBLISH_GROUP_ID = 'ai.picovoice'
PUBLISH_VERSION = '1.2.0'
PUBLISH_VERSION = '2.0.0'
PUBLISH_ARTIFACT_ID = 'cobra-android'
}

android {
compileSdkVersion defaultTargetSdkVersion
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 21
targetSdkVersion defaultTargetSdkVersion
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

Expand All @@ -36,13 +34,9 @@ if (file("${rootDir}/publish-mavencentral.gradle").exists()) {
apply from: "${rootDir}/publish-mavencentral.gradle"
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
}

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

preBuild.dependsOn copyLibs
preBuild.dependsOn(copyLibs)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021-2022 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 @@ -21,19 +21,26 @@
**/
public class Cobra {

private static String _sdk = "android";

static {
System.loadLibrary("pv_cobra");
}

private long handle;

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

/**
* Constructor.
*
* @param accessKey AccessKey obtained from Picovoice Console
* @throws CobraException if there is an error while initializing Cobra.
*/
public Cobra(String accessKey) throws CobraException {
CobraNative.setSdk(Cobra._sdk);
handle = CobraNative.init(accessKey);
}

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 @@ -14,16 +14,18 @@

class CobraNative {

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);
static native long init(String accessKey) throws CobraException;

static native void delete(long object);

static native float process(long object, short[] pcm);
static native float process(long object, short[] pcm) throws CobraException;

}
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 CobraActivationException(Throwable cause) {
public CobraActivationException(String message) {
super(message);
}

public CobraActivationException(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 CobraActivationLimitException(Throwable cause) {
public CobraActivationLimitException(String message) {
super(message);
}

public CobraActivationLimitException(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 CobraActivationRefusedException(Throwable cause) {
public CobraActivationRefusedException(String message) {
super(message);
}

public CobraActivationRefusedException(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 CobraActivationThrottledException(Throwable cause) {
public CobraActivationThrottledException(String message) {
super(message);
}

public CobraActivationThrottledException(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 @@ -10,12 +10,46 @@

package ai.picovoice.cobra;

import android.annotation.SuppressLint;

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

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

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

public CobraException(String message, String[] messageStack) {
super(message);
this.message = message;
this.messageStack = messageStack;
}

public String[] getMessageStack() {
return this.messageStack;
}

@SuppressLint("DefaultLocale")
@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 CobraIOException(Throwable cause) {
public CobraIOException(String message) {
super(message);
}

public CobraIOException(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 CobraInvalidArgumentException(Throwable cause) {
public CobraInvalidArgumentException(String message) {
super(message);
}

public CobraInvalidArgumentException(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 CobraInvalidStateException(Throwable cause) {
public CobraInvalidStateException(String message) {
super(message);
}

public CobraInvalidStateException(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 CobraKeyException(Throwable cause) {
public CobraKeyException(String message) {
super(message);
}

public CobraKeyException(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 CobraMemoryException(Throwable cause) {
public CobraMemoryException(String message) {
super(message);
}

public CobraMemoryException(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 CobraRuntimeException(Throwable cause) {
public CobraRuntimeException(String message) {
super(message);
}

public CobraRuntimeException(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 CobraStopIterationException(Throwable cause) {
public CobraStopIterationException(String message) {
super(message);
}

public CobraStopIterationException(String message, String[] messageStack) {
super(message, messageStack);
}
}
Loading