Skip to content

Commit

Permalink
v1.0 android (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErisMik authored Feb 14, 2023
1 parent 2865b27 commit 8cae6fc
Show file tree
Hide file tree
Showing 79 changed files with 2,694 additions and 5 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/android-appcenter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Android AppCenter Tests

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

defaults:
run:
working-directory: demo/android/Activity

jobs:
build:
name: Run Android Tests on AppCenter
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup Node.js environment
uses: actions/[email protected]

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

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

- name: Binding pre-build
run: ./gradlew assemble
working-directory: binding/android

- name: Copy test_resources
run: ./copy_test_resources.sh

- name: Inject AccessKey
run: echo pvTestingAccessKey="${{secrets.PV_VALID_ACCESS_KEY}}" >> local.properties

- name: Build app
run: ./gradlew assembleDebug

- name: Build androidTest
run: ./gradlew assembleAndroidTest

- name: Run tests on AppCenter
run: appcenter test run espresso
--token ${{secrets.APPCENTERAPITOKEN}}
--app "Picovoice/Koala-Android"
--devices "Picovoice/android-min-max"
--app-path koala-activity-demo-app/build/outputs/apk/debug/koala-activity-demo-app-debug.apk
--test-series "koala-android"
--locale "en_US"
--build-dir koala-activity-demo-app/build/outputs/apk/androidTest/debug
83 changes: 83 additions & 0 deletions .github/workflows/android-perf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Android Performance

on:
workflow_dispatch:
push:
branches: [ main ]
paths:
- '.github/workflows/android-perf.yml'
- 'lib/android/**'
- 'lib/common/**'
- 'resources/audio_samples/**'
pull_request:
branches: [ main, 'v[0-9]+.[0-9]+']
paths:
- '.github/workflows/android-perf.yml'
- 'lib/android/**'
- 'lib/common/**'
- 'resources/audio_samples/**'

defaults:
run:
working-directory: demo/android/Activity

jobs:
build:
name: Run Android Speed Tests on AppCenter
runs-on: ubuntu-latest

strategy:
matrix:
device: [single-android, 32bit-android]
include:
- device: single-android
performanceThresholdSec: 0.4
- device: 32bit-android
performanceThresholdSec: 3.0

steps:
- uses: actions/checkout@v2

- name: Setup Node.js environment
uses: actions/[email protected]

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

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

- name: Copy test_resources
run: ./copy_test_resources.sh

- name: Inject AccessKey
run: echo pvTestingAccessKey="${{secrets.PV_VALID_ACCESS_KEY}}" >> local.properties

- name: Inject Number of Iterations
run: echo numTestIterations="30" >> local.properties

- name: Inject Proc Performance Threshold
run: echo performanceThresholdSec="${{ matrix.performanceThresholdSec }}" >> local.properties

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build app
run: ./gradlew assembleDebug

- name: Build androidTest
run: ./gradlew assembleAndroidTest

- name: Run tests on AppCenter
run: appcenter test run espresso
--token ${{secrets.APPCENTERAPITOKEN}}
--app "Picovoice/Koala-Android"
--devices "Picovoice/${{ matrix.device }}"
--app-path koala-activity-demo-app/build/outputs/apk/debug/koala-activity-demo-app-debug.apk
--test-series "koala-android"
--locale "en_US"
--build-dir koala-activity-demo-app/build/outputs/apk/androidTest/debug

46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ Koala is an on-device noise suppression engine. Koala is:
- [AccessKey](#accesskey)
- [Demos](#demos)
- [Python](#python-demos)
- [Android](#android-demo)
- [iOS](#ios-demo)
- [C](#c-demos)
- [Web](#web-demo)
- [SDKs](#sdks)
- [Python](#python)
- [Android](#android)
- [iOS](#ios)
- [C](#c)
- [Web](#web)
Expand Down Expand Up @@ -65,6 +67,13 @@ koala_demo_file \

Replace `${ACCESS_KEY}` with yours obtained from Picovoice Console.

### Android Demo

Using [Android Studio](https://developer.android.com/studio/index.html), open
[demo/android/Activity](./demo/android/Activity) as an Android project and then run the application.

Replace `"${YOUR_ACCESS_KEY_HERE}"` in the file [MainActivity.java](./demo/android/Activity/koala-activity-demo-app/src/main/java/ai/picovoice/koalaactivitydemo/MainActivity.java) with your `AccessKey`.

### iOS Demo

Copy your `AccessKey` into the `ACCESS_KEY` variable inside [`ViewModel.swift`](./demo/ios/KoalaDemo/KoalaDemo/ViewModel.swift).
Expand Down Expand Up @@ -153,6 +162,42 @@ while True:

Finally, when done be sure to explicitly release the resources using `koala.delete()`.

### Android

To include the package in your Android project, ensure you have included `mavenCentral()` in your top-level `build.gradle` file and then add the following to your app's `build.gradle`:

```groovy
dependencies {
implementation 'ai.picovoice:koala-android:${LATEST_VERSION}'
}
```

Create an instance of the engine and enhance audio in real-time:

```java
import ai.picovoice.koala.*;

final String accessKey = "${ACCESS_KEY}"; // AccessKey obtained from Picovoice Console (https://console.picovoice.ai/)

short[] getNextAudioFrame() {
// .. get audioFrame
return audioFrame;
}

try {
Koala koala = new Koala.Builder()
.setAccessKey(accessKey)
.build(appContext);

while true {
short[] enhancedFrame = koala.process(getNextAudioFrame());
};

} catch (KoalaException ex) { }
```

Replace `${ACCESS_KEY}` with yours obtained from [Picovoice Console](https://console.picovoice.ai/).

### iOS

Create an instance of the engine and enhance audio:
Expand Down Expand Up @@ -265,7 +310,6 @@ for (;;) {

Replace `${ACCESS_KEY}` with yours obtained from [Picovoice Console](https://console.picovoice.ai/). Finally, when done release the resources using `koala.release()`.


## Releases

### v1.0.0 February 7th, 2023
Expand Down
12 changes: 12 additions & 0 deletions binding/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.iml
.gradle
/local.properties
/.idea/
.DS_Store
/build
/captures
test_resources
.settings
.classpath
.project
publish-mavencentral.gradle
80 changes: 80 additions & 0 deletions binding/android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Koala Binding for Android

## Koala Noise Suppression Engine

Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)

Koala is an on-device noise suppression engine. Koala is:

- Private; All voice processing runs locally.
- Cross-Platform:
- Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64)
- Android and iOS
- Chrome, Safari, Firefox, and Edge
- Raspberry Pi (4, 3) and NVIDIA Jetson Nano

## Compatibility

- Android 5.0 (SDK 21+)

## Installation

Koala is hosted on Maven Central. To include the package in your Android project, ensure you have
included `mavenCentral()` in your top-level `build.gradle` file and then add the following to your
app's `build.gradle`:

```groovy
dependencies {
// ...
implementation 'ai.picovoice:koala-android:${VERSION}'
}
```

## AccessKey

Koala requires a valid Picovoice `AccessKey` at initialization. `AccessKey` acts as your credentials when using Koala SDKs.
You can get your `AccessKey` for free. Make sure to keep your `AccessKey` secret.
Signup or Login to [Picovoice Console](https://console.picovoice.ai/) to get your `AccessKey`.

## Usage

Create an instance of the engine with the Koala Builder class by passing in the `accessKey` and Android app context:

```java
import ai.picovoice.koala.*;

final String accessKey = "${ACCESS_KEY}"; // AccessKey provided by Picovoice Console (https://console.picovoice.ai/)
try {
Koala koala = new Koala.Builder()
.setAccessKey(accessKey)
.build(appContext);
} catch (KoalaException ex) { }
```

Enhance audio:

```java
short[] getNextAudioFrame() {
// .. get audioFrame
return audioFrame;
}

while true {
short[] enhancedFrame = koala.process(getNextAudioFrame());
}
```

In case the next audio frame does not directly follow the previous one, call `reset()`:
```java
koala.reset();
```

When done, resources have to be released explicitly:

```java
koala.delete();
```

## Demo App

For example usage refer to our [Android demo application](../../demo/android).
25 changes: 25 additions & 0 deletions binding/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ext {
defaultTargetSdkVersion = 31
}

buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
17 changes: 17 additions & 0 deletions binding/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
Binary file added binding/android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions binding/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Jun 29 22:27:49 PDT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Loading

0 comments on commit 8cae6fc

Please sign in to comment.