Java FreeTTS缺少语音

我写了一个小程序,它应该简单地用Java进行文本转换。

我的class级看起来像这样:

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

我很确定语法(和东西)是正确的,但我的voice总是null

我认为项目中没有找到“kevin16”也没有包括在内,但我根本无法弄清楚如何为我的项目添加任何语音。 为了获得依赖关系,我使用maven

  net.sf.sociaal freetts 1.2.2  

除了声音之外,一切都在那里。 从我读到的,我认为“kevin16”应该包含在FreeTTS中。 任何想法如何继续? 我怎样才能添加声音? 我也发现了一些关于MBROLA东西,但这让我更加不清楚:/

谢谢你的帮助。

我有完全相同的问题。 当我尝试调用voiceManager.getVoices()时,我得到了空列表。 问题是, freetts.voices系统属性未设置。 所以,添加以下行修复了我的问题:

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

现在,我能够使用kevinkevin16的声音。

希望这可以帮助。

你有没有在任何地方打电话给说话的方法?

尝试这样的事情:

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

我打算用它来说你比我更熟悉Maven服务器,但是我也经常使用FreeTTS和MBROLA语音,而且我从来没有遇到过只引用freetts库的问题在我的项目中。

如果您想要查看MBROLA,我确实有一个关于如何在这里设置它的正确线程

这对我来说也不起作用。 我使用了不同的存储库(您必须更改您的POM文件)。 我使用了以下依赖项:

   org.mobicents.external.freetts freetts 1.2.2   org.mobicents.external.freetts en_us 1.2.2   org.mobicents.external.freetts cmu_us_kal 1.2.2   org.mobicents.external.freetts cmu_time_awb 1.2.2   org.mobicents.external.freetts cmulex 1.2.2   org.mobicents.external.freetts cmutimelex 1.2.2   org.mobicents.external.freetts cmudict04 1.2.2  

为此,我使用了以下存储库:

  sonatype-oss-public https://oss.sonatype.org/content/groups/public/  true   true   

只需在主页中添加第一行即可

在此处输入代码

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