javamavenfreetts

Java FreeTTS missing Voice


I wrote a small program, which should simply do a text-to-speach in Java.

My Class looks like this:

import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

public class TalkResource {

private static final String VOICENAME_kevin = "kevin16";
private final String text; // string to speech

public TalkResource(String text) {
    this.text = text;
}

public void speak() {
    Voice voice;
    VoiceManager voiceManager = VoiceManager.getInstance();
    voice = voiceManager.getVoice(VOICENAME_kevin);
    voice.allocate();

    String newText = "example";
    voice.speak(newText);
    }
}

I'm pretty sure the syntax (and stuff) is correct, but my voice is always null.

I assume that "kevin16" is not found nor included to the project, but I simply can't figure out how to add any voice to my project. To get the dependencies, I use maven.

<dependency>
    <groupId>net.sf.sociaal</groupId>
    <artifactId>freetts</artifactId>
    <version>1.2.2</version>
</dependency>

Everything is there, except the voices. From what I read, I assume that "kevin16" should be included in FreeTTS. Any ideas how to go on? How can I add a voice? Also I found something about MBROLA, but that just made things even more unclear for me :/

Thanks for any help.


Solution

  • I had exactly same problem. I was getting empty list when I tried to call voiceManager.getVoices(). The problem was, freetts.voices system property was not set. So, adding the following line fixed my problem:

    System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
    

    Now, I am able to use kevin or kevin16 voices.

    Hope this helps.