diff --git a/binding/android/Orca/orca/src/main/java/ai/picovoice/orca/Orca.java b/binding/android/Orca/orca/src/main/java/ai/picovoice/orca/Orca.java index 7bf9adf1..fdd265a3 100644 --- a/binding/android/Orca/orca/src/main/java/ai/picovoice/orca/Orca.java +++ b/binding/android/Orca/orca/src/main/java/ai/picovoice/orca/Orca.java @@ -50,6 +50,7 @@ public OrcaStream(long stream) { * `getValidCharacters()`. Custom pronunciations can be embedded in the text via the * syntax `{word|pronunciation}`. The pronunciation is expressed in ARPAbet format, * e.g.: `I {liv|L IH V} in {Sevilla|S EH V IY Y AH}`. + * @return The output audio. If none is available, null is returned. * @throws OrcaException if there is an error while synthesizing audio. */ public short[] synthesize(String text) throws OrcaException { @@ -60,7 +61,7 @@ public short[] synthesize(String text) throws OrcaException { } if (stream == 0) { throw new OrcaInvalidStateException( - "Attempted to call OrcaStream synthesize after close." + "Attempted to call OrcaStream synthesize without an open stream." ); } @@ -72,6 +73,7 @@ public short[] synthesize(String text) throws OrcaException { /** * Flushes remaining text. The returned audio contains the speech representation of the text. * + * @return Any remaining output audio. If none is available, null is returned. * @throws OrcaException if there is an error while synthesizing audio. */ public short[] flush() throws OrcaException { @@ -82,7 +84,7 @@ public short[] flush() throws OrcaException { } if (stream == 0) { throw new OrcaInvalidStateException( - "Attempted to call OrcaStream flush after close." + "Attempted to call OrcaStream flush without an open stream." ); } @@ -160,7 +162,7 @@ public void delete() { * syntax `{word|pronunciation}`. The pronunciation is expressed in ARPAbet format, * e.g.: `I {liv|L IH V} in {Sevilla|S EH V IY Y AH}`. * @param params Global parameters for synthesized text. See 'OrcaSynthesizeParams' for details. - * @return The output audio. + * @return The output audio and alignments data. * @throws OrcaException if there is an error while synthesizing audio. */ public OrcaAudio synthesize(String text, OrcaSynthesizeParams params) throws OrcaException { @@ -189,6 +191,7 @@ public OrcaAudio synthesize(String text, OrcaSynthesizeParams params) throws Orc * @param outputPath Absolute path to the output audio file. The output file is saved as * `WAV (.wav)` and consists of a single mono channel. * @param params Global parameters for synthesized text. See 'OrcaSynthesizeParams' for details. + * @return The alignments data. * @throws OrcaException if there is an error while synthesizing audio to file. */ public OrcaWord[] synthesizeToFile( diff --git a/binding/android/OrcaTestApp/orca-test-app/src/androidTest/java/ai/picovoice/orca/testapp/OrcaTest.java b/binding/android/OrcaTestApp/orca-test-app/src/androidTest/java/ai/picovoice/orca/testapp/OrcaTest.java index 28c10c00..7e3c4427 100644 --- a/binding/android/OrcaTestApp/orca-test-app/src/androidTest/java/ai/picovoice/orca/testapp/OrcaTest.java +++ b/binding/android/OrcaTestApp/orca-test-app/src/androidTest/java/ai/picovoice/orca/testapp/OrcaTest.java @@ -283,45 +283,45 @@ public void testSynthesizeAlignment() throws OrcaException { Objects.equals(modelFileUsed, EXACT_ALIGNMENT_TEST_MODEL_IDENTIFIER)); } - @Test - public void testSynthesizeToFileAlignment() throws OrcaException { - final File outputFile = new File( - appContext.getFilesDir(), - "text.wav"); - OrcaWord[] result = orca.synthesizeToFile( - textAlignment, - outputFile.getAbsolutePath(), - new OrcaSynthesizeParams.Builder() - .setRandomState(randomState) - .build()); - outputFile.delete(); - - final OrcaWord[] synthesizeTestData = new OrcaWord[alignments.size()]; - for (int i = 0; i < alignments.size(); i++) { - final JsonObject testData = alignments.get(i).getAsJsonObject(); - final String word = testData.get("word").getAsString(); - final float startSec = testData.get("start_sec").getAsFloat(); - final float endSec = testData.get("end_sec").getAsFloat(); - final JsonArray phonemesJson = testData.getAsJsonArray("phonemes"); - final OrcaPhoneme[] phonemes = new OrcaPhoneme[phonemesJson.size()]; - for (int j = 0; j < phonemesJson.size(); j++) { - final JsonObject phonemeJson = phonemesJson.get(j).getAsJsonObject(); - phonemes[j] = new OrcaPhoneme( - phonemeJson.get("phoneme").getAsString(), - phonemeJson.get("start_sec").getAsFloat(), - phonemeJson.get("end_sec").getAsFloat()); - } - synthesizeTestData[i] = new OrcaWord( - word, - startSec, - endSec, - phonemes); + @Test + public void testSynthesizeToFileAlignment() throws OrcaException { + final File outputFile = new File( + appContext.getFilesDir(), + "text.wav"); + OrcaWord[] result = orca.synthesizeToFile( + textAlignment, + outputFile.getAbsolutePath(), + new OrcaSynthesizeParams.Builder() + .setRandomState(randomState) + .build()); + outputFile.delete(); + + final OrcaWord[] synthesizeTestData = new OrcaWord[alignments.size()]; + for (int i = 0; i < alignments.size(); i++) { + final JsonObject testData = alignments.get(i).getAsJsonObject(); + final String word = testData.get("word").getAsString(); + final float startSec = testData.get("start_sec").getAsFloat(); + final float endSec = testData.get("end_sec").getAsFloat(); + final JsonArray phonemesJson = testData.getAsJsonArray("phonemes"); + final OrcaPhoneme[] phonemes = new OrcaPhoneme[phonemesJson.size()]; + for (int j = 0; j < phonemesJson.size(); j++) { + final JsonObject phonemeJson = phonemesJson.get(j).getAsJsonObject(); + phonemes[j] = new OrcaPhoneme( + phonemeJson.get("phoneme").getAsString(), + phonemeJson.get("start_sec").getAsFloat(), + phonemeJson.get("end_sec").getAsFloat()); } - validateMetadata( - result, - synthesizeTestData, - Objects.equals(modelFileUsed, EXACT_ALIGNMENT_TEST_MODEL_IDENTIFIER)); + synthesizeTestData[i] = new OrcaWord( + word, + startSec, + endSec, + phonemes); } + validateMetadata( + result, + synthesizeTestData, + Objects.equals(modelFileUsed, EXACT_ALIGNMENT_TEST_MODEL_IDENTIFIER)); + } @Test public void testSynthesizeSpeechRate() throws OrcaException { @@ -360,7 +360,6 @@ public void testSynthesizeRandomState() throws OrcaException { final OrcaAudio randomState1 = orca.synthesize( text, new OrcaSynthesizeParams.Builder() - .setSpeechRate(0.7f) .setRandomState(1) .build()); assertTrue(randomState1.getPcm().length > 0); @@ -369,7 +368,6 @@ public void testSynthesizeRandomState() throws OrcaException { final OrcaAudio randomState2 = orca.synthesize( text, new OrcaSynthesizeParams.Builder() - .setSpeechRate(1.3f) .setRandomState(2) .build()); assertTrue(randomState2.getPcm().length > 0);