Skip to content

Commit

Permalink
v2.1 Android (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErisMik authored Dec 5, 2024
1 parent 73f9406 commit c84bf53
Show file tree
Hide file tree
Showing 19 changed files with 367 additions and 107 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/android-browserstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
- run:
pip3 install requests

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

- name: Copy test_resources
Expand Down Expand Up @@ -70,8 +70,8 @@ jobs:
--access_key "${{secrets.BROWSERSTACK_ACCESS_KEY}}"
--project_name "Cheetah-Android"
--devices "android-min-max"
--app_path "cheetah-test-app/build/outputs/apk/debug/cheetah-test-app-debug.apk"
--test_path "cheetah-test-app/build/outputs/apk/androidTest/debug/cheetah-test-app-debug-androidTest.apk"
--app_path "cheetah-test-app/build/outputs/apk/en/debug/cheetah-test-app-en-debug.apk"
--test_path "cheetah-test-app/build/outputs/apk/androidTest/en/debug/cheetah-test-app-en-debug-androidTest.apk"

build-integ:
name: Run Android Integration Tests on BrowserStack
Expand All @@ -90,10 +90,10 @@ jobs:
- name: Install AppCenter CLI
run: npm install -g appcenter-cli

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

- name: Copy test_resources
Expand Down Expand Up @@ -128,6 +128,6 @@ jobs:
--access_key "${{secrets.BROWSERSTACK_ACCESS_KEY}}"
--project_name "Cheetah-Android-Integration"
--devices "android-min-max"
--app_path "cheetah-test-app/build/outputs/apk/release/cheetah-test-app-release.apk"
--test_path "cheetah-test-app/build/outputs/apk/androidTest/release/cheetah-test-app-release-androidTest.apk"
--app_path "cheetah-test-app/build/outputs/apk/en/release/cheetah-test-app-en-release.apk"
--test_path "cheetah-test-app/build/outputs/apk/androidTest/en/release/cheetah-test-app-en-release-androidTest.apk"

8 changes: 4 additions & 4 deletions .github/workflows/android-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
- run:
pip3 install requests

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

- name: Copy test_resources
Expand Down Expand Up @@ -89,6 +89,6 @@ jobs:
--access_key "${{secrets.BROWSERSTACK_ACCESS_KEY}}"
--project_name "Cheetah-Android-Performance"
--devices "${{ matrix.device }}"
--app_path "cheetah-test-app/build/outputs/apk/debug/cheetah-test-app-debug.apk"
--test_path "cheetah-test-app/build/outputs/apk/androidTest/debug/cheetah-test-app-debug-androidTest.apk"
--app_path "cheetah-test-app/build/outputs/apk/en/debug/cheetah-test-app-en-debug.apk"
--test_path "cheetah-test-app/build/outputs/apk/androidTest/en/debug/cheetah-test-app-en-debug-androidTest.apk"

2 changes: 1 addition & 1 deletion binding/android/Cheetah/cheetah/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.0.0'
PUBLISH_VERSION = '2.1.0'
PUBLISH_ARTIFACT_ID = 'cheetah-android'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +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
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
4 changes: 2 additions & 2 deletions binding/android/CheetahTestApp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
.externalNativeBuild
release
test_resources
cheetah_params.pv
cheetah_params*.pv

*.wav
*.jks
!.dummy.jks
!.dummy.jks
8 changes: 7 additions & 1 deletion binding/android/CheetahTestApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ buildscript {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1352/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'com.android.tools.build:gradle:8.2.2'
}
}

allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/aipicovoice-1352/'
}
}
}

Expand Down
78 changes: 58 additions & 20 deletions binding/android/CheetahTestApp/cheetah-test-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,54 @@ android {
testBuildType("release")
}

def testDataFile = file('../../../../resources/.test/test_data.json')
def parsedJson = new groovy.json.JsonSlurper().parseText(testDataFile.text)
def languages = []
parsedJson.tests.parameters.each { a ->
languages.add(a.language)
}

flavorDimensions "language"
productFlavors {
en {
getIsDefault().set(true)
}

languages.each { language ->
"$language" {
applicationIdSuffix ".$language"

}
}

all { flavor ->
delete fileTree("$projectDir/src/main/assets") {
exclude '**/.gitkeep'
}
String suffix = (flavor.name != "en") ? "_${flavor.name}" : ""
task("${flavor.name}CopyParams", type: Copy) {
from("$projectDir/../../../../lib/common/")
include("cheetah_params${suffix}.pv")
into("$projectDir/src/main/assets/models")
}
task("${flavor.name}CopyAudio", type: Copy) {
description = "Copy ${flavor.name} audio resources"
from("$projectDir/../../../../resources/audio_samples/")
include("test${suffix}.wav")
into("$projectDir/src/main/assets/audio_samples")
}
}
}
sourceSets {
androidTest {
java {
if (System.getProperty("testBuildType", "debug") == "perf") {
exclude "**/CheetahTest.java"
exclude "**/StandardTests.java"
exclude "**/IntegrationTest.java"
exclude "**/LanguageTests.java"
} else if (System.getProperty("testBuildType", "debug") == "integ") {
exclude "**/CheetahTest.java"
exclude "**/StandardTests.java"
exclude "**/LanguageTests.java"
exclude "**/PerformanceTest.java"
} else {
exclude "**/IntegrationTest.java"
Expand All @@ -89,18 +129,6 @@ android {
}
}

task("copyParams", type: Copy) {
from("$projectDir/../../../../lib/common/")
include("cheetah_params.pv")
into("$projectDir/src/main/assets/models")
}
task("copyAudio", type: Copy) {
description = "Copy audio resources"
from("$projectDir/../../../../resources/audio_samples/")
include("test.wav")
into("$projectDir/src/main/assets/audio_samples/")
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -109,14 +137,17 @@ android {
lint {
abortOnError false
}

namespace 'ai.picovoice.cheetah.testapp'
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'ai.picovoice:cheetah-android:2.0.0'
implementation 'com.google.code.gson:gson:2.10'
implementation 'ai.picovoice:cheetah-android:2.1.0'

// Espresso UI Testing
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand All @@ -127,8 +158,15 @@ dependencies {
}

afterEvaluate {
tasks."mergeDebugAssets".dependsOn "copyParams"
tasks."mergeReleaseAssets".dependsOn "copyParams"
tasks."mergeDebugAssets".dependsOn "copyAudio"
tasks."mergeReleaseAssets".dependsOn "copyAudio"
}
android.productFlavors.all {
flavor ->
tasks."merge${flavor.name.capitalize()}DebugAssets".dependsOn "${flavor.name}CopyParams"
tasks."merge${flavor.name.capitalize()}ReleaseAssets".dependsOn "${flavor.name}CopyParams"
tasks."generate${flavor.name.capitalize()}ReleaseLintVitalReportModel".dependsOn "${flavor.name}CopyParams"
tasks."lintVitalAnalyze${flavor.name.capitalize()}Release".dependsOn "${flavor.name}CopyParams"
tasks."merge${flavor.name.capitalize()}DebugAssets".dependsOn "${flavor.name}CopyAudio"
tasks."merge${flavor.name.capitalize()}ReleaseAssets".dependsOn "${flavor.name}CopyAudio"
tasks."generate${flavor.name.capitalize()}ReleaseLintVitalReportModel".dependsOn "${flavor.name}CopyAudio"
tasks."lintVitalAnalyze${flavor.name.capitalize()}Release".dependsOn "${flavor.name}CopyAudio"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2024 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 @@ -22,6 +22,7 @@

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -50,11 +51,58 @@ public void Setup() throws IOException {
assetManager = testContext.getAssets();
extractAssetsRecursively("test_resources");
testResourcesPath = new File(appContext.getFilesDir(), "test_resources").getAbsolutePath();
defaultModelPath = new File(testResourcesPath, "cheetah_params.pv").getAbsolutePath();
defaultModelPath = new File(testResourcesPath, "model_files/cheetah_params.pv").getAbsolutePath();

accessKey = appContext.getString(R.string.pvTestingAccessKey);
}

public static String getTestDataString() throws IOException {
Context testContext = InstrumentationRegistry.getInstrumentation().getContext();
AssetManager assetManager = testContext.getAssets();

InputStream is = new BufferedInputStream(assetManager.open("test_resources/test_data.json"), 256);
ByteArrayOutputStream result = new ByteArrayOutputStream();

byte[] buffer = new byte[256];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
result.write(buffer, 0, bytesRead);
}

return result.toString("UTF-8");
}

protected static float getWordErrorRate(
String transcript,
String expectedTranscript,
boolean useCER) {
String splitter = (useCER) ? "" : " ";
return (float) levenshteinDistance(
transcript.split(splitter),
expectedTranscript.split(splitter)) / transcript.length();
}

private static int levenshteinDistance(String[] words1, String[] words2) {
int[][] res = new int[words1.length + 1][words2.length + 1];
for (int i = 0; i <= words1.length; i++) {
res[i][0] = i;
}
for (int j = 0; j <= words2.length; j++) {
res[0][j] = j;
}
for (int i = 1; i <= words1.length; i++) {
for (int j = 1; j <= words2.length; j++) {
res[i][j] = Math.min(
Math.min(
res[i - 1][j] + 1,
res[i][j - 1] + 1),
res[i - 1][j - 1] + (words1[i - 1].equalsIgnoreCase(words2[j - 1]) ? 0 : 1)
);
}
}
return res[words1.length][words2.length];
}

private void extractAssetsRecursively(String path) throws IOException {
String[] list = assetManager.list(path);
if (list.length > 0) {
Expand Down
Loading

0 comments on commit c84bf53

Please sign in to comment.