I started to use MaryTTS in a java project and it’s working fine but with an english voice :
public static void main(String[] args) throws MaryConfigurationException, InterruptedException, SynthesisException {
// init CLI options, args
MaryInterface marytts = new LocalMaryInterface();
Set<String> voices = marytts.getAvailableVoices();
System.out.println(marytts.getAvailableVoices());
marytts.setVoice(voices.iterator().next());
AudioInputStream audio = marytts.generateAudio("Hello world");
AudioPlayer player = new AudioPlayer(audio);
player.start();
player.join();
I need to set the voice to French. So this is my pom.xml :
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>de.dfki.mary</groupId>
<artifactId>voice-cmu-slt-hsmm</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>de.dfki.mary</groupId>
<artifactId>marytts-lang-fr</artifactId>
<version>5.2.1</version>
</dependency>
</dependencies>
Those are my dependencies, so I have the maryTTS one, and the one that should bring me the french voice that I take on MavenSearch : https://search.maven.org/artifact/de.dfki.mary/marytts-lang-fr/5.2.1/jar
It seems like french is not implemented because if I do this :
Set<String> voices = maryTTS.getAvailableVoices();
for(String v : voices){
System.out.println("Voice available: " + v);
}
This is what I get in console : [cmu-slt-hsmm]
What can I do more to set the voice in French ?
EDIT : Ok so I am getting close to an answer, I downloaded two jar : marytts.lang.fr and voice-enst-camille-hsmm that I added to my project and if I do something like this :
MaryInterface marytts = new LocalMaryInterface(); marytts.setLocale(Locale.FRENCH);
marytts.setVoice("upmc-pierre-hsmm");
AudioInputStream audio = marytts.generateAudio("Bonjour TEST TEST TEST ");
AudioPlayer player = new AudioPlayer(audio);
player.start();
player.join();
It work, I have the french voice like I want BUT I also would like when I send a txt file, my program create a wav file and read it. This is working but only in english :
Options options = new Options();
Option outputOption = Option.builder("o").longOpt(OUT_OPT).hasArg().argName("FILE").desc("Write output to FILE")
.required().build();
Option inputOption = Option.builder("i").longOpt(IN_OPT).hasArg().argName("FILE")
.desc("Read input from FILEn(otherwise, read from command line argument)").build();
options.addOption(outputOption);
options.addOption(inputOption);
HelpFormatter formatter = new HelpFormatter();
CommandLineParser parser = new DefaultParser();
CommandLine line = null;
try {
line = parser.parse(options, args);
} catch (ParseException e) {
System.err.println("Error parsing command line options: " + e.getMessage());
formatter.printHelp(NAME, options, true);
System.exit(1);
}
// get output option
String outputFileName = null;
if (line.hasOption(OUT_OPT)) {
outputFileName = line.getOptionValue(OUT_OPT);
if (!FilenameUtils.getExtension(outputFileName).equals("wav")) {
outputFileName += ".wav";
}
} else {
System.err.println("Please provide an output wav filename.");
formatter.printHelp(NAME, options, true);
System.exit(1);
}
// get input
String inputText = null;
if (line.hasOption(IN_OPT)) {
String inputFileName = line.getOptionValue(IN_OPT);
File file = new File(inputFileName);
try {
inputText = FileUtils.readFileToString(file);
} catch (IOException e) {
System.err.println("Could not read from file " + inputFileName + ": " + e.getMessage());
System.exit(1);
}
} else {
try {
inputText = line.getArgList().get(0);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
if (inputText == null) {
System.err.println("Please provide an input text.");
formatter.printHelp(NAME, options, true);
System.exit(1);
}
// init mary
MaryInterface mary = new LocalMaryInterface();
// synthesize
AudioInputStream audio = null;
try {
audio = mary.generateAudio(inputText);
} catch (SynthesisException e) {
System.err.println("Synthesis failed: " + e.getMessage());
System.exit(1);
}
// write to output
double[] samples = MaryAudioUtils.getSamplesAsDoubleArray(audio);
try {
MaryAudioUtils.writeWavFile(samples, outputFileName, audio.getFormat());
System.out.println("Output written to " + outputFileName);
} catch (IOException e) {
System.err.println("Could not write to file: " + outputFileName + "n" + e.getMessage());
System.exit(1);
}
So to have it in french I just added :
mary.setLocale(Locale.FRENCH);
mary.setVoice("upmc-pierre-hsmm");
under
MaryInterface mary = new LocalMaryInterface();
But I have this error message when I try my app in terminal :
Exception in thread "main" java.lang.IllegalArgumentException: No such voice: upmc-pierre-hsmm
at marytts.LocalMaryInterface.setVoice(LocalMaryInterface.java:182)
at de.dfki.mary.Txt2Wav.main(Txt2Wav.java:94)
EDIT : If I do this in my intellij and not in my terminal it’s working fine
Advertisement
Answer
So the solution to have maryTTS in french is to add those Jar in your project : -https://gitlab.istic.univ-rennes1.fr/amucheri/avatar-beta2/-/blob/9f1027251cefa136f34e96d30789319aafec5625/lib/marytts-lang-fr-5.2.jar
this one to have the french local.
For the voices, you can add the jar or I think add this maven dependencies will also work :
-https://mvnrepository.com/artifact/de.dfki.mary/voice-enst-camille-hsmm/5.2
you can change the URL to find the voice you want.
By passing my arguments :
-i hello.txt -o hello.wav
In the arguments of my project in IntelliJ :
it work.
If someone know why it’s working like this and not in my terminal I’m glad to hear it.