Java FreeTTS missing Voice

戏子无情 提交于 2019-12-03 16:42:42

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.

MadCharlie

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

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>

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