From ce016b1d72b09cb6bd086fa113edb6e697cc5893 Mon Sep 17 00:00:00 2001 From: Bert Frees Date: Mon, 22 Jul 2024 15:37:57 +0200 Subject: [PATCH] Make tts-adapter-espeak compatible with espeak-ng see https://github.com/daisy/pipeline/issues/704 --- bom/pom.xml | 2 +- .../org/daisy/pipeline/tts/espeak/impl/ESpeakEngine.java | 7 +++++-- .../org/daisy/pipeline/tts/espeak/impl/EspeakTest.java | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bom/pom.xml b/bom/pom.xml index d8cdfce52..67ab9f038 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -460,7 +460,7 @@ org.daisy.pipeline.modules tts-adapter-espeak - 3.0.12 + 3.0.13-SNAPSHOT org.daisy.pipeline.modules diff --git a/tts/tts-adapters/tts-adapter-espeak/src/main/java/org/daisy/pipeline/tts/espeak/impl/ESpeakEngine.java b/tts/tts-adapters/tts-adapter-espeak/src/main/java/org/daisy/pipeline/tts/espeak/impl/ESpeakEngine.java index 6315107f2..608894b1f 100644 --- a/tts/tts-adapters/tts-adapter-espeak/src/main/java/org/daisy/pipeline/tts/espeak/impl/ESpeakEngine.java +++ b/tts/tts-adapters/tts-adapter-espeak/src/main/java/org/daisy/pipeline/tts/espeak/impl/ESpeakEngine.java @@ -12,6 +12,7 @@ import java.util.IllformedLocaleException; import java.util.Locale; import java.util.Map; +import java.util.Optional; import java.util.Scanner; import java.util.Set; import java.util.regex.Matcher; @@ -118,7 +119,9 @@ public Collection getAvailableVoices() throws SynthesisException, // Second: get the list of the voices for the found languages. // White spaces are not allowed in voice names result = new ArrayList(); - Matcher mr = Pattern.compile("^\\s*[0-9]+\\s+(?[-a-z]+)\\s+(?[FfMm-]\\s+)?(?[^ ]+)").matcher(""); + Matcher mr = Pattern.compile( + "^\\s*[0-9]+\\s+(?[-a-zA-Z0-9]+)\\s+((--/)?(?[FfMm-])\\s+)?(?[^ ]+)" + ).matcher(""); for (String lang : languages) { new CommandRunner(mESpeakPath, "--voices=" + lang) .consumeOutput(stream -> { @@ -131,7 +134,7 @@ public Collection getAvailableVoices() throws SynthesisException, String name = mr.group("name"); try { Locale locale = (new Locale.Builder()).setLanguageTag(mr.group("locale").replace("_", "-")).build(); - Gender gender = "f".equals(mr.group("gender").trim().toLowerCase()) + Gender gender = "f".equals(Optional.ofNullable(mr.group("gender")).orElse("m").toLowerCase()) ? Gender.FEMALE_ADULT : Gender.MALE_ADULT; result.add(new Voice(getProvider().getName(), name, locale, gender)); diff --git a/tts/tts-adapters/tts-adapter-espeak/src/test/java/org/daisy/pipeline/tts/espeak/impl/EspeakTest.java b/tts/tts-adapters/tts-adapter-espeak/src/test/java/org/daisy/pipeline/tts/espeak/impl/EspeakTest.java index 780854b2c..28d3df99e 100644 --- a/tts/tts-adapters/tts-adapter-espeak/src/test/java/org/daisy/pipeline/tts/espeak/impl/EspeakTest.java +++ b/tts/tts-adapters/tts-adapter-espeak/src/test/java/org/daisy/pipeline/tts/espeak/impl/EspeakTest.java @@ -74,7 +74,7 @@ public void speakWithVoices() throws Throwable { + "small test"), null, resource).audio; - sizes.add(getSize(audio) / 4); //div 4 helps being more robust to tiny differences + sizes.add(getSize(audio) / 4); // div 4 helps being more robust to tiny differences totalVoices++; } engine.releaseThreadResources(resource); @@ -82,7 +82,7 @@ public void speakWithVoices() throws Throwable { //this number will be very low if the voice names are not properly retrieved float diversity = Float.valueOf(sizes.size()) / totalVoices; - Assert.assertTrue(diversity > 0.4); + Assert.assertTrue(diversity > 0.2); } @Test