Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 293
DasSaffe Avatar asked Jan 06 '15 22:01

DasSaffe


4 Answers

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.

like image 126
utsav_deep Avatar answered Sep 25 '22 08:09

utsav_deep


Do you ever call the your speak method anywhere?

Try something like this:

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

public class TalkResource {

    private static final String VOICENAME_kevin = "kevin16";

    public TalkResource(String sayText) {
        Voice voice;
        VoiceManager voiceManager = VoiceManager.getInstance();
        voice = voiceManager.getVoice(VOICENAME_kevin);
        voice.allocate();

        voice.speak(sayText);
    }

    public static void main(String []args) {
        new TalkResource("hello");
    }
}

I'm going to take a stab at it and say that you are more familiar with Maven servers than I am, however I do also frequently play with FreeTTS and MBROLA voices, and I've never had a problem with just referencing the freetts libraries in my project.

If you feel like checking out MBROLA, I do have a decent thread on how to set it up here

like image 20
MadCharlie Avatar answered Sep 27 '22 08:09

MadCharlie


That didn't work for me either. I used a different repository (you have to change your POM file). I used the following dependencies:

<dependencies>
    <dependency>
        <groupId>org.mobicents.external.freetts</groupId>
        <artifactId>freetts</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.mobicents.external.freetts</groupId>
        <artifactId>en_us</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.mobicents.external.freetts</groupId>
        <artifactId>cmu_us_kal</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.mobicents.external.freetts</groupId>
        <artifactId>cmu_time_awb</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.mobicents.external.freetts</groupId>
        <artifactId>cmulex</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.mobicents.external.freetts</groupId>
        <artifactId>cmutimelex</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.mobicents.external.freetts</groupId>
        <artifactId>cmudict04</artifactId>
        <version>1.2.2</version>
    </dependency>

For this I used the following repositories:

<repository>
    <id>sonatype-oss-public</id>
    <url>https://oss.sonatype.org/content/groups/public/</url>
    <releases>
        <enabled>true</enabled>
    </releases>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>
like image 31
Traple Avatar answered Sep 23 '22 08:09

Traple


Just simply add First line in your main

enter code here

public static void main(String[] args) throws Exception{
    // TODO code application logic here
 System.setProperty("freetts.voices", 
 "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
  String message = "Hello world! This is a test program";
  Mehrunisa mehrunisa = new Mehrunisa(message);
  mehrunisa.speak();
 }
like image 44
Ali Hassan Avatar answered Sep 26 '22 08:09

Ali Hassan