Skip to content

Commit

Permalink
Make tts-adapter-espeak compatible with espeak-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
bertfrees committed Sep 23, 2024
1 parent b2c0458 commit 801696a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
<dependency>
<groupId>org.daisy.pipeline.modules</groupId>
<artifactId>tts-adapter-espeak</artifactId>
<version>3.0.12</version>
<version>3.0.13-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.daisy.pipeline.modules</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +119,9 @@ public Collection<Voice> 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<Voice>();
Matcher mr = Pattern.compile("^\\s*[0-9]+\\s+(?<locale>[-a-z]+)\\s+(?<gender>[FfMm-]\\s+)?(?<name>[^ ]+)").matcher("");
Matcher mr = Pattern.compile(
"^\\s*[0-9]+\\s+(?<locale>[-a-zA-Z0-9]+)\\s+((--/)?(?<gender>[FfMm-])\\s+)?(?<name>[^ ]+)"
).matcher("");
for (String lang : languages) {
new CommandRunner(mESpeakPath, "--voices=" + lang)
.consumeOutput(stream -> {
Expand All @@ -131,7 +134,7 @@ public Collection<Voice> 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));
Expand Down

0 comments on commit 801696a

Please sign in to comment.