Skip to content

Commit

Permalink
try fix
Browse files Browse the repository at this point in the history
  • Loading branch information
albho committed Nov 25, 2024
1 parent e302669 commit 10fd1f5
Show file tree
Hide file tree
Showing 15 changed files with 496 additions and 442 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/android-browserstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,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 @@ -91,10 +91,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
4 changes: 2 additions & 2 deletions .github/workflows/android-demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- 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: Build
Expand Down
4 changes: 2 additions & 2 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
2 changes: 1 addition & 1 deletion binding/android/LeopardTestApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'com.android.tools.build:gradle:8.2.2'
}
}

Expand Down
3 changes: 3 additions & 0 deletions binding/android/LeopardTestApp/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# 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
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Jun 29 23:02:09 PDT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ android {
lint {
abortOnError false
}
namespace 'ai.picovoice.leopard.testapp'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022-2023 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 @@ -12,7 +12,6 @@

package ai.picovoice.leopard.testapp;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
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.
Unless required by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied. See the License for the specific language governing permissions and
limitations under the License.
*/

package ai.picovoice.leopard.testapp;

import static org.junit.Assert.*;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import ai.picovoice.leopard.Leopard;
import ai.picovoice.leopard.LeopardTranscript;

@RunWith(Parameterized.class)
public class DiarizationTests extends BaseTest {
@Parameterized.Parameter(value = 0)
public String language;

@Parameterized.Parameter(value = 1)
public String modelFile;

@Parameterized.Parameter(value = 2)
public String testAudioFile;

@Parameterized.Parameter(value = 3)
public LeopardTranscript.Word[] expectedWords;

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> initParameters() throws IOException {
String testDataJsonString = getTestDataString();

JsonParser parser = new JsonParser();
JsonObject testDataJson = parser.parse(testDataJsonString).getAsJsonObject();
JsonArray languageTests = testDataJson
.getAsJsonObject("tests")
.getAsJsonArray("diarization_tests");

List<Object[]> parameters = new ArrayList<>();
for (int i = 0; i < languageTests.size(); i++) {
JsonObject testData = languageTests.get(i).getAsJsonObject();

String language = testData.get("language").getAsString();
String audioFile = testData.get("audio_file").getAsString();
JsonArray words = testData.get("words").getAsJsonArray();

String modelFile;
if (language.equals("en")) {
modelFile = "model_files/leopard_params.pv";
} else {
modelFile = String.format("model_files/leopard_params_%s.pv", language);
}

String testAudioFile = String.format("audio_samples/%s", audioFile);

LeopardTranscript.Word[] paramWords = new LeopardTranscript.Word[words.size()];
for (int j = 0; j < words.size(); j++) {
JsonObject wordObject = words.get(j).getAsJsonObject();

String word = wordObject.get("word").getAsString();
int speakerTag = wordObject.get("speaker_tag").getAsInt();

paramWords[j] = new LeopardTranscript.Word(
word,
0.f,
0.f,
0.f,
speakerTag
);
}

parameters.add(new Object[]{
language,
modelFile,
testAudioFile,
paramWords
});
}

return parameters;
}

@Test
public void testDiarizationMultipleSpeakers() throws Exception {
String modelPath = new File(testResourcesPath, modelFile).getAbsolutePath();
Leopard leopard = new Leopard.Builder()
.setAccessKey(accessKey)
.setModelPath(modelPath)
.setEnableDiarization(true)
.build(appContext);

File audioFile = new File(testResourcesPath, testAudioFile);
short[] pcm = readAudioFile(audioFile.getAbsolutePath());

LeopardTranscript result = leopard.process(pcm);

assertEquals(result.getWordArray().length, expectedWords.length);
for (int i = 0; i < result.getWordArray().length; i++) {
assertEquals(result.getWordArray()[i].getWord(), expectedWords[i].getWord());
assertEquals(result.getWordArray()[i].getSpeakerTag(), expectedWords[i].getSpeakerTag());
}
leopard.delete();
}
}
Loading

0 comments on commit 10fd1f5

Please sign in to comment.