0

How Do I Make the Mary TTS 5.2 Library Compatible with JDK 11?

As I mentioned in the title, I need to voice a text received with the help of a CDI Bean in Turkish. This is built for a sound button that will work when the button is clicked on a web page. The problem is that Mary TTS is compatible with JDK 8 but I am using Jakarta specification and working with JDK 11. After downloading it from Mary TTS's web page, I ran it with JDK 8. The result was very good. But I couldn't get it to work in my project.

CDI Bean Code:

protected int bytesRead = 0;

public void guvenlikKodSeslendir() {
    try {
        // MaryTTS arayüzünü oluşturun
        MaryInterface maryTts = new LocalMaryInterface();

        // Türkçe yerel ayarını yükleyin
        maryTts.setLocale(new Locale("tr"));

        //Kullanılacak ses modelini ayarlayın
        maryTts.setVoice("dfki-pavoque-neutral");

        // Seslendirilecek metni ayarlayın
        String text = "Merhaba, dünya!";

        // Metni seslendirin ve ses dalgası verisini alın
        AudioInputStream audio = maryTts.generateAudio(str);

        // Ses dalgasını çalacak bir SourceDataLine oluşturun
        try (SourceDataLine line = AudioSystem.getSourceDataLine(audio.getFormat())) {
            line.open(audio.getFormat());
            line.start();
            byte[] buffer = new byte[4096];
            int bytesRead = 0;
            while ((bytesRead = audio.read(buffer)) != -1) {
                line.write(buffer, 0, bytesRead);
            }
            line.drain();
            line.stop();
        }
    } catch (IOException | LineUnavailableException | MaryConfigurationException | SynthesisException e) {
        e.printStackTrace();
    }
}

The code from the facelet page will be replaced with the "str" statement. I've corrected it for clarity.

I downloaded Mary TTS version 5.2 from mary.defki.de. I start the file "marytts-server.bat" in the "bin" folder. I also have JDK 11 version on my computer. When I start the file in this way without changing the path variable, the following error message is displayed in the console window. Output:

Java version "11.0.18" 2023-01-17 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.18+9-LTS-195)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.18+9-LTS-195, mixed mode)
MARY server 5.2 starting as a HTTP server...WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass$3$1 (file:/C:/Users/MFC/Documents/marytts-5.2/lib/marytts-client-5.2-jar-with-dependencies.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass$3$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
  started in 4.966 s on port 59125

The above error message does not occur if JDK 8 is used.

I would like to summarize the example by making a standard class with a main method so that the subject can be better understood. Class Code:

package tr.com.fatih.beans;

import java.io.IOException;
import java.util.Locale;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import marytts.LocalMaryInterface;
import marytts.exceptions.MaryConfigurationException;
import marytts.exceptions.SynthesisException;

public class MaryTTSExample {
    public static void main(String[] args) {
        try {
            LocalMaryInterface maryTts = new LocalMaryInterface();
            maryTts.setLocale(new Locale("tr"));
            maryTts.setVoice("dfki-pavoque-neutral");
            String text = "Merhaba, bu bir deneme metnidir.";
            AudioInputStream audio = maryTts.generateAudio(text);
            try (SourceDataLine line = AudioSystem.getSourceDataLine(audio.getFormat())) {
                line.open(audio.getFormat());
                line.start();
                byte[] buffer = new byte[4096];
                int bytesRead = 0;
                while ((bytesRead = audio.read(buffer)) != -1) {
                    line.write(buffer, 0, bytesRead);
                }
                line.drain();
                line.stop();
            }
        } catch (IOException | IllegalArgumentException | LineUnavailableException | MaryConfigurationException | SynthesisException e) {
            e.printStackTrace();
        }
    }
}

NetBeans gives me a warning when I run the code.

Output:

marytts.exceptions.MaryConfigurationException: Cannot start MARY server
    at marytts.LocalMaryInterface.<init>(LocalMaryInterface.java:66)
    at tr.com.fatih.beans.MaryTTSExample.main(MaryTTSExample.java:16)
Caused by: java.lang.Exception: Problem starting module Synthesis
    at marytts.server.Mary.startModules(Mary.java:151)
    at marytts.server.Mary.startup(Mary.java:297)
    at marytts.server.Mary.startup(Mary.java:204)
    at marytts.util.MaryRuntimeUtils.ensureMaryStarted(MaryRuntimeUtils.java:72)
    at marytts.LocalMaryInterface.<init>(LocalMaryInterface.java:64)
    ... 1 more
Caused by: marytts.exceptions.MaryConfigurationException: Cannot build unit selection voice 'dfki-ot'
    at marytts.unitselection.UnitSelectionVoice.<init>(UnitSelectionVoice.java:218)
    at marytts.unitselection.UnitSelectionSynthesizer.startup(UnitSelectionSynthesizer.java:94)
    at marytts.modules.Synthesis.startupSynthesizers(Synthesis.java:73)
    at marytts.modules.Synthesis.startup(Synthesis.java:65)
    at marytts.server.Mary.startModules(Mary.java:149)
    ... 5 more
Caused by: marytts.exceptions.NoSuchPropertyException: Cannot read file `voices\dfki-ot\halfphoneFeatures_ac.mry'. Check property `voice.dfki-ot.featureFile' in configuration files
    at marytts.server.MaryProperties.needFilename(MaryProperties.java:389)
    at marytts.unitselection.UnitSelectionVoice.<init>(UnitSelectionVoice.java:107)
    ... 9 more
Exception in thread "Thread-1" java.lang.IllegalStateException: MARY system is not running
    at marytts.server.Mary.shutdown(Mary.java:371)
    at marytts.server.Mary$2.run(Mary.java:290)
  • 1
    The first log is a warning in a Groovy class that you don't show. Is that the problem? Is it preventing you of executing? The second log is an error that is unrelated to the warning. Are these two separate issues? Have you read the message at the bottom of the error? `Cannot read file \`voices\dfki-ot\halfphoneFeatures_ac.mry'. Check property \`voice.dfki-ot.featureFile' in configuration files`. Looks to be a configuration problem. – aled Jun 02 '23 at 17:18
  • Inside the Voice.config file there is this line: voice.dfki-ot.featureFile = voices/dfki-ot/halfphoneFeatures_ac.mry File path: "lib\voices\dfki-ot\halfphoneFeatures_ac.mry" voice.config file path (it's in the voice-dfki-ot-5.2.jar file): "lib\voice-dfki-ot-5.2.jar" The reason I'm giving this information is because I want to know if I have set the path to the "halfphoneFeatures_ac.mry" file in the Voice.config file correctly. Since I have not used Grovial before, I cannot guess if it interferes with the work. I created the project as a standard web project. I'm not using maven or grovial – Mehmet Fatih ÇİN Jun 02 '23 at 21:06

0 Answers0