From 801696a3c49d9810538038e827538f669730e697 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 +++++-- 2 files changed, 6 insertions(+), 3 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));