FreeTTS - java.lang.ClassNotFoundException: javax.speech.EngineCentral

点点圈 提交于 2019-12-08 07:39:21

问题


I have a problem, and I know this might similiar to the ones that are online, but I have followed every instruction I have found online and I am still getting this problem.

Basically I am making a GUI with a Virtual Keyboard, and whatever the user types, I want the user to be able to click a button and I want a speech synthesis to convert the text-to-speech. I have looked online and found that the easiest and most common open software used was freeTSS. I have installed freeTSS and followed the instructions.

I have then taken the following code from the online community:

import java.util.*; import javax.speech.*;        import javax.speech.synthesis.*;    

public class Text2Speech     {    
    String speaktext; 
    public void dospeak(String speak,String  voicename)    
    {    
        speaktext=speak;    
        String voiceName =voicename;    
        try    
        {    
            SynthesizerModeDesc desc = new SynthesizerModeDesc(null,"general",  Locale.US,null,null);    
            Synthesizer synthesizer =  Central.createSynthesizer(desc);    
            synthesizer.allocate();    
            synthesizer.resume();     
            desc = (SynthesizerModeDesc)  synthesizer.getEngineModeDesc();     
            Voice[] voices = desc.getVoices();      
            Voice voice = null;
            for (int i = 0; i < voices.length; i++)    
            {    
                if (voices[i].getName().equals(voiceName))    
                {    
                    voice = voices[i];    
                    break;     
                }     
            }    
            synthesizer.getSynthesizerProperties().setVoice(voice);    
            System.out.print("Speaking : "+speaktext);    
            synthesizer.speakPlainText(speaktext, null);    
            synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);    
            synthesizer.deallocate();    
        }    
        catch (Exception e)   
        {    
            String message = " missing speech.properties in " + System.getProperty("user.home") + "\n"; 
            System.out.println (System.getProperty( "java.home" ) );
            System.out.println(""+e);    
            System.out.println(message);    
        }    
    }    

    public static void main(String[] args)    
    {    
        Text2Speech obj=new Text2Speech(); obj.dospeak("Hello i am kevin ","kevin16");    
    }     }

When I run it the first time, I get the following error:

java.lang.ClassNotFoundException: javax.speech.EngineCentral

Interestingly, when I close down the error and run it again (both times through the main method), I get an error thrown saying that I am missing the speech.properties. This is weird as I ran the HelloWorld.jar from the command prompt the first time and I was told where to add the speech properties too. The java -jar bin/HelloWorld.jar works fine in command prompt, but somehow something doesn't work in the code I share above.

I have followed the instructions on: http://www.ryan-h.com/uncategorized/java-speech-jsapi-freetts/ and still I can't solve the problem. I am using BlueJ as my IDE, yes I know it isn't that good and I should use Eclipse, but when I make GUI projects I rather use BlueJ rather than Eclipse. Would that make a difference though?

Also final question, I am suppose to make my program into an application, so the user who isn't a computer programmer can use it easily. Would the user need to go through the hideous procedure of installing Jaspi, and freetts, copy jar files, copy speech.properties and so on?

来源:https://stackoverflow.com/questions/30090534/freetts-java-lang-classnotfoundexception-javax-speech-enginecentral

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