voce-简单Java代码不工作

voce-简单Java代码不工作,java,text-to-speech,Java,Text To Speech,我最近安装了Voce,并在我的Java应用程序中使用它。在Eclipse中,我将voce-0.9.1/voce-0.9.1/lib中的JAR文件添加到Java构建路径中的库中。根据文档,我认为这段代码应该可以工作: import voce.SpeechSynthesizer; public class Test { public static void main(String[] args) { // System.out.println("Speaking")

我最近安装了Voce,并在我的Java应用程序中使用它。在Eclipse中,我将voce-0.9.1/voce-0.9.1/lib中的JAR文件添加到Java构建路径中的库中。根据文档,我认为这段代码应该可以工作:

import voce.SpeechSynthesizer;

public class Test
{
    public static void main(String[] args)
    {
        // System.out.println("Speaking");
        SpeechSynthesizer speaker = new SpeechSynthesizer("speaker");
        speaker.synthesize("hello");
        // System.out.println("Spoken");
        speaker.destroy();
    }
}
当我取消对输出语句的注释时,程序输出“Speaking”,然后几乎立即输出“speaked”,而不发出声音。我的音量调大了。synthesis()是说字符串还是我忘记了一些初始化?你能给我一些应该有用的代码吗

答复

下面是有效的代码(我使用SpeechInterface中的静态方法,而不是SpeechSynthesizer对象):


speaker.synthesis
可能在另一个线程中运行。因此您可以立即看到Speaked。在它说“Speaked”之后,Eclipse说应用程序已终止,但我没有听到任何“hello”。您正在使用的库是什么?Voce:谢谢!成功了。把你的评论变成一个答案,我会接受的。
public class Test
{
    public static void main(String[] args)
    {
        voce.SpeechInterface.init("../../../lib", true, false, "", "");
        System.out.println("Speaking");
        voce.SpeechInterface.synthesize("hello");
        System.out.println("Spoken");
        try { Thread.sleep(1000); } catch(Exception ex) {}
        voce.SpeechInterface.destroy();
    }
}