mirror of
https://github.com/Picovoice/porcupine.git
synced 2022-01-28 03:27:53 +03:00
Github actions java add platforms and non-English tests (#601)
This commit is contained in:
27
.github/workflows/java.yml
vendored
27
.github/workflows/java.yml
vendored
@@ -34,8 +34,12 @@ defaults:
|
||||
working-directory: binding/java
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
build-github-hosted:
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@@ -54,3 +58,22 @@ jobs:
|
||||
|
||||
- name: Test
|
||||
run: ./gradlew test -DpvTestingAccessKey="${{secrets.PV_VALID_ACCESS_KEY}}"
|
||||
|
||||
build-self-hosted:
|
||||
runs-on: ${{ matrix.machine }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
machine: [rpi2, rpi3, rpi4, jetson, beaglebone]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Validate Gradle wrapper
|
||||
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
|
||||
|
||||
- name: Build
|
||||
run: ./gradlew assemble
|
||||
|
||||
- name: Test
|
||||
run: ./gradlew test -DpvTestingAccessKey="${{secrets.PV_VALID_ACCESS_KEY}}"
|
||||
@@ -120,7 +120,7 @@ class Utils {
|
||||
return resourceDirectoryPath;
|
||||
}
|
||||
|
||||
private static String getEnvironmentName() throws RuntimeException {
|
||||
public static String getEnvironmentName() throws RuntimeException {
|
||||
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
|
||||
if (os.contains("mac") || os.contains("darwin")) {
|
||||
return "mac";
|
||||
|
||||
@@ -22,17 +22,62 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class PorcupineTest {
|
||||
|
||||
private static final String ENVIRONMENT_NAME;
|
||||
private Porcupine porcupine;
|
||||
private String accessKey = System.getProperty("pvTestingAccessKey");
|
||||
|
||||
static {
|
||||
ENVIRONMENT_NAME = Utils.getEnvironmentName();
|
||||
}
|
||||
|
||||
private static String appendLanguage(String s, String language) {
|
||||
if (language == "en")
|
||||
return s;
|
||||
return s + "_" + language;
|
||||
}
|
||||
|
||||
private static String getTestKeywordPath(String language, String keyword) {
|
||||
return Paths.get(System.getProperty("user.dir"))
|
||||
.resolve("../../resources")
|
||||
.resolve(appendLanguage("keyword_files", language))
|
||||
.resolve(ENVIRONMENT_NAME)
|
||||
.resolve(keyword + "_" + ENVIRONMENT_NAME + ".ppn")
|
||||
.toString();
|
||||
}
|
||||
|
||||
private static String getTestModelPath(String language) {
|
||||
return Paths.get(System.getProperty("user.dir"))
|
||||
.resolve("../../lib/common")
|
||||
.resolve(appendLanguage("porcupine_params", language)+".pv")
|
||||
.toString();
|
||||
}
|
||||
|
||||
private static String getTestAudioFilePath(String audioFileName) {
|
||||
return Paths.get(System.getProperty("user.dir"))
|
||||
.resolve("../../resources/audio_samples")
|
||||
.resolve(audioFileName)
|
||||
.toString();
|
||||
}
|
||||
|
||||
private static String[] getTestKeywordPaths(String language, String[] keywords) {
|
||||
String keywordPaths[] = new String[keywords.length];
|
||||
for (int i=0; i<keywords.length; i++) {
|
||||
keywordPaths[i] = getTestKeywordPath(language, keywords[i]);
|
||||
}
|
||||
return keywordPaths;
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
porcupine.delete();
|
||||
@@ -65,15 +110,10 @@ public class PorcupineTest {
|
||||
assertTrue(porcupine.getSampleRate() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProcess() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
porcupine = new Porcupine.Builder()
|
||||
.setAccessKey(accessKey)
|
||||
.setBuiltInKeyword(Porcupine.BuiltInKeyword.PORCUPINE)
|
||||
.build();
|
||||
|
||||
private void runTestCase(String audioFileName, ArrayList<Integer> expectedResults) throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
int frameLen = porcupine.getFrameLength();
|
||||
File testAudioPath = new File("../../resources/audio_samples/porcupine.wav");
|
||||
String audioFilePath = getTestAudioFilePath(audioFileName);
|
||||
File testAudioPath = new File(audioFilePath);
|
||||
|
||||
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(testAudioPath);
|
||||
assertEquals(audioInputStream.getFormat().getFrameRate(), 16000);
|
||||
@@ -90,18 +130,30 @@ public class PorcupineTest {
|
||||
|
||||
ByteBuffer.wrap(pcm).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(porcupineFrame);
|
||||
int result = porcupine.process(porcupineFrame);
|
||||
assertTrue(result == -1 || result == 0);
|
||||
assertTrue(result >= -1);
|
||||
if (result >= 0) {
|
||||
results.add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(results.size() == 1 && results.get(0) == 0);
|
||||
assertEquals(results, expectedResults);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProcessMultiple() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
void testSingleKeyword() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
porcupine = new Porcupine.Builder()
|
||||
.setAccessKey(accessKey)
|
||||
.setBuiltInKeyword(Porcupine.BuiltInKeyword.PORCUPINE)
|
||||
.build();
|
||||
|
||||
runTestCase(
|
||||
"porcupine.wav",
|
||||
new ArrayList<>(Arrays.asList(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultipleKeywords() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
final Porcupine.BuiltInKeyword[] keywords = new Porcupine.BuiltInKeyword[]{
|
||||
Porcupine.BuiltInKeyword.ALEXA,
|
||||
Porcupine.BuiltInKeyword.AMERICANO,
|
||||
@@ -119,32 +171,97 @@ public class PorcupineTest {
|
||||
.setBuiltInKeywords(keywords)
|
||||
.build();
|
||||
|
||||
int frameLen = porcupine.getFrameLength();
|
||||
File testAudioPath = new File("../../resources/audio_samples/multiple_keywords.wav");
|
||||
runTestCase(
|
||||
"multiple_keywords.wav",
|
||||
new ArrayList<>(Arrays.asList(7, 0, 1, 2, 3, 4, 5, 6, 7, 8)));
|
||||
}
|
||||
|
||||
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(testAudioPath);
|
||||
assertEquals(audioInputStream.getFormat().getFrameRate(), 16000);
|
||||
@Test
|
||||
void testSingleKeywordDe() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
final String language = "de";
|
||||
final String keywords[] = {"heuschrecke"};
|
||||
porcupine = new Porcupine.Builder()
|
||||
.setAccessKey(accessKey)
|
||||
.setModelPath(getTestModelPath(language))
|
||||
.setKeywordPaths(getTestKeywordPaths(language, keywords))
|
||||
.build();
|
||||
runTestCase(
|
||||
"heuschrecke.wav",
|
||||
new ArrayList<>(Arrays.asList(0)));
|
||||
}
|
||||
|
||||
int byteDepth = audioInputStream.getFormat().getFrameSize();
|
||||
int bufferSize = frameLen * byteDepth;
|
||||
byte[] pcm = new byte[bufferSize];
|
||||
short[] porcupineFrame = new short[frameLen];
|
||||
int numBytesRead = 0;
|
||||
ArrayList<Integer> results = new ArrayList<>();
|
||||
while ((numBytesRead = audioInputStream.read(pcm)) != -1) {
|
||||
@Test
|
||||
void testMultipleKeywordsDe() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
final String language = "de";
|
||||
final String keywords[] = {"ananas", "heuschrecke", "leguan", "stachelschwein"};
|
||||
porcupine = new Porcupine.Builder()
|
||||
.setAccessKey(accessKey)
|
||||
.setModelPath(getTestModelPath(language))
|
||||
.setKeywordPaths(getTestKeywordPaths(language, keywords))
|
||||
.build();
|
||||
|
||||
if (numBytesRead / byteDepth == frameLen) {
|
||||
runTestCase(
|
||||
"multiple_keywords_de.wav",
|
||||
new ArrayList<>(Arrays.asList(0, 1, 2, 3)));
|
||||
}
|
||||
|
||||
ByteBuffer.wrap(pcm).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(porcupineFrame);
|
||||
int result = porcupine.process(porcupineFrame);
|
||||
assertTrue(result >= -1 && result < keywords.length);
|
||||
if (result >= 0) {
|
||||
results.add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void testSingleKeywordEs() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
final String language = "es";
|
||||
final String keywords[] = {"manzana"};
|
||||
porcupine = new Porcupine.Builder()
|
||||
.setAccessKey(accessKey)
|
||||
.setModelPath(getTestModelPath(language))
|
||||
.setKeywordPaths(getTestKeywordPaths(language, keywords))
|
||||
.build();
|
||||
|
||||
ArrayList<Integer> expectedResults = new ArrayList<>(Arrays.asList(7, 0, 1, 2, 3, 4, 5, 6, 7, 8));
|
||||
assertEquals(results, expectedResults);
|
||||
runTestCase(
|
||||
"manzana.wav",
|
||||
new ArrayList<>(Arrays.asList(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultipleKeywordsEs() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
final String language = "es";
|
||||
final String keywords[] = {"emparedado", "leopardo", "manzana"};
|
||||
porcupine = new Porcupine.Builder()
|
||||
.setAccessKey(accessKey)
|
||||
.setModelPath(getTestModelPath(language))
|
||||
.setKeywordPaths(getTestKeywordPaths(language, keywords))
|
||||
.build();
|
||||
|
||||
runTestCase(
|
||||
"multiple_keywords_es.wav",
|
||||
new ArrayList<>(Arrays.asList(0, 1, 2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSingleKeywordFr() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
final String language = "fr";
|
||||
final String keywords[] = {"mon chouchou"};
|
||||
porcupine = new Porcupine.Builder()
|
||||
.setAccessKey(accessKey)
|
||||
.setModelPath(getTestModelPath(language))
|
||||
.setKeywordPaths(getTestKeywordPaths(language, keywords))
|
||||
.build();
|
||||
|
||||
runTestCase(
|
||||
"mon_chouchou.wav",
|
||||
new ArrayList<>(Arrays.asList(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMultipleKeywordsFr() throws IOException, UnsupportedAudioFileException, PorcupineException {
|
||||
final String language = "fr";
|
||||
final String keywords[] = {"framboise", "mon chouchou", "parapluie"};
|
||||
porcupine = new Porcupine.Builder()
|
||||
.setAccessKey(accessKey)
|
||||
.setModelPath(getTestModelPath(language))
|
||||
.setKeywordPaths(getTestKeywordPaths(language, keywords))
|
||||
.build();
|
||||
|
||||
runTestCase(
|
||||
"multiple_keywords_fr.wav",
|
||||
new ArrayList<>(Arrays.asList(0, 1, 0, 2)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user