Java FreeTTS missing Voice

对着背影说爱祢 提交于 2020-01-01 06:13:22

问题


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.


回答1:


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.




回答2:


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




回答3:


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>



回答4:


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();
 }


来源:https://stackoverflow.com/questions/27808248/java-freetts-missing-voice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!