-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
496 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
binding/android/LeopardTestApp/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ android { | |
lint { | ||
abortOnError false | ||
} | ||
namespace 'ai.picovoice.leopard.testapp' | ||
} | ||
|
||
dependencies { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
.../leopard-test-app/src/androidTest/java/ai/picovoice/leopard/testapp/DiarizationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.