Skip to content

Commit

Permalink
v2.0 (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
laves authored Oct 26, 2023
1 parent 9b6e090 commit ab49620
Show file tree
Hide file tree
Showing 99 changed files with 2,312 additions and 1,404 deletions.
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
11 changes: 0 additions & 11 deletions .github/workflows/ios-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js LTS
uses: actions/setup-node@v3
with:
node-version: lts/*

- name: Install Cocoapods
run: gem install cocoapods

- name: Install AppCenter CLI
run: npm install -g appcenter-cli

- name: Make build dir
run: mkdir ddp

- name: Run Cocoapods
run: pod install

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: pip install -r requirements.txt

- name: Test
run: python cobra_demo_file.py --access_key ${{secrets.PV_VALID_ACCESS_KEY}} --input_audio_path ../../res/audio/sample.wav
run: python cobra_demo_file.py --access_key ${{secrets.PV_VALID_ACCESS_KEY}} --input_wav_path ../../res/audio/sample.wav

build-self-hosted:
runs-on: ${{ matrix.machine }}
Expand All @@ -59,4 +59,4 @@ jobs:
run: pip3 install -r requirements.txt

- name: Test
run: python3 cobra_demo_file.py --access_key ${{secrets.PV_VALID_ACCESS_KEY}} --input_audio_path ../../res/audio/sample.wav
run: python3 cobra_demo_file.py --access_key ${{secrets.PV_VALID_ACCESS_KEY}} --input_wav_path ../../res/audio/sample.wav
6 changes: 2 additions & 4 deletions .github/workflows/python-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches: [ main ]
paths:
- '.github/workflows/python-perf.yml'
- 'binding/python/test_cobra_perf.py'
- 'lib/beaglebone/**'
- 'lib/jetson/**'
Expand All @@ -16,6 +17,7 @@ on:
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '.github/workflows/python-perf.yml'
- 'binding/python/test_cobra_perf.py'
- 'lib/beaglebone/**'
- 'lib/jetson/**'
Expand Down Expand Up @@ -47,8 +49,6 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Python '3.10'
uses: actions/setup-python@v2
Expand Down Expand Up @@ -96,8 +96,6 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Pre-build dependencies
run: python3 -m pip install --upgrade pip
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches: [ main ]
paths:
- '.github/workflows/python.yml'
- 'binding/python/**'
- '!binding/python/README.md'
- 'lib/beaglebone/**'
Expand All @@ -17,6 +18,7 @@ on:
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+' ]
paths:
- '.github/workflows/python.yml'
- 'binding/python/**'
- '!binding/python/README.md'
- 'lib/beaglebone/**'
Expand All @@ -42,8 +44,6 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
Expand All @@ -69,8 +69,6 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Pre-build dependencies
run: python3 -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/web-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand Down
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();
}
}
Loading

0 comments on commit ab49620

Please sign in to comment.